Skip to content

Commit

Permalink
width bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 14, 2024
1 parent 605135e commit 9b1037d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
3 changes: 2 additions & 1 deletion R/tt_bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ bootstrap_setting <- function(x, new, component = "row") {
idx <- grep("tinytable columns before this", out)
} else if (component == "cell") {
idx <- grep("tinytable cells before this", out)
# idx <- 8 # hard-coded location (dangerous?)
} else if (component == "css") {
idx <- grep("</style>", out, fixed = TRUE)
idx <- grep("</style>", out, fixed = TRUE)[1]
} else if (component == "newrows") {
idx <- grep("tinytable new rows before this", out)
}
Expand Down
53 changes: 24 additions & 29 deletions inst/templates/bootstrap.html
Original file line number Diff line number Diff line change
@@ -1,44 +1,17 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>$tinytable_TABLE_ID</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script>
function styleCell(i, j, css_id) {
var table = document.getElementById("$tinytable_TABLE_ID");
table.rows[i].cells[j].classList.add(css_id);
}
function insertSpanRow(i, colspan, content) {
var table = document.getElementById('$tinytable_TABLE_ID');
var newRow = table.insertRow(i);
var newCell = newRow.insertCell(0);
newCell.setAttribute("colspan", colspan);
newCell.innerText = content;
}
// tinytable cells before this
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<style>
table {
width: auto;
margin-left: auto;
margin-right: auto;
}
</style>
</style>
</head>

<body>
<div class="container">
<table class="$tinytable_BOOTSTRAP_CLASS" id="$tinytable_TABLE_ID" data-quarto-disable-processing="true">
<table class="$tinytable_BOOTSTRAP_CLASS" id="$tinytable_TABLE_ID" style="width: auto; margin-left: auto; margin-right: auto;" data-quarto-disable-processing='true'>
<thead>
$tinytable_BOOTSTRAP_CAPTION
$tinytable_BOOTSTRAP_HEADER
Expand All @@ -50,6 +23,28 @@
</table>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script>
function styleCell(i, j, css_id) {
var table = document.getElementById("$tinytable_TABLE_ID");
table.rows[i].cells[j].classList.add(css_id);
}
function insertSpanRow(i, colspan, content) {
var table = document.getElementById('$tinytable_TABLE_ID');
var newRow = table.insertRow(i);
var newCell = newRow.insertCell(0);
newCell.setAttribute("colspan", colspan);
newCell.innerText = content;
}
// tinytable cells before this
</script>

</body>

</html>
Expand Down
2 changes: 1 addition & 1 deletion vignettes/tutorial.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ tt(x, align = "ccrrl")
The `width` arguments accepts a number between 0 and 1, indicating what proportion of the linewidth the table should cover:

```{r}
tt(x, width = 0.3)
tt(x, width = 0.5)
```

```{r}
Expand Down

0 comments on commit 9b1037d

Please sign in to comment.