[FIX] параметры размещения плавающих объектов: крупный рисунок остаётся на своей странице

This commit is contained in:
Arseny
2026-09-02 13:16:18 +03:00
parent d5b6f4b89e
commit 95bd42cea4
4 changed files with 15 additions and 5 deletions
+1 -1
View File
@@ -96,7 +96,7 @@ def figure(tokens: list[Token]) -> str:
caption = escape_latex(m.group(1)) caption = escape_latex(m.group(1))
lines = [ lines = [
"\\begin{figure}[ht]", "\\begin{figure}[htb]",
" \\centering", " \\centering",
rf" \includegraphics[width={width}]{{\detokenize{{{path}}}}}", rf" \includegraphics[width={width}]{{\detokenize{{{path}}}}}",
] ]
+1 -1
View File
@@ -191,7 +191,7 @@ def captioned_table(tokens: list[Token]) -> str:
return "\n".join( return "\n".join(
[ [
"\\begin{table}[ht]", "\\begin{table}[htb]",
f" \\caption{{{caption}}}", f" \\caption{{{caption}}}",
" \\centering", " \\centering",
_tabular(rows, aligns), _tabular(rows, aligns),
+10
View File
@@ -15,6 +15,16 @@ PREAMBLE = r"""\documentclass[a4paper, 14pt]{extarticle}
\graphicspath{ {./} {./images/} } \graphicspath{ {./} {./images/} }
\usepackage{float} \usepackage{float}
\usepackage[section]{placeins} \usepackage[section]{placeins}
% Значения по умолчанию требуют, чтобы текст занимал не меньше 80 % страницы,
% а иллюстрация внизу — не больше 30 %. Из-за этого крупный рисунок не
% помещался на своей странице и уезжал, оставляя её наполовину пустой.
\renewcommand{\textfraction}{0.05}
\renewcommand{\topfraction}{0.95}
\renewcommand{\bottomfraction}{0.95}
\renewcommand{\floatpagefraction}{0.75}
\setcounter{topnumber}{3}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{5}
\usepackage{wrapfig} \usepackage{wrapfig}
\sloppy \sloppy
\setlength{\emergencystretch}{2em} \setlength{\emergencystretch}{2em}
+3 -3
View File
@@ -48,7 +48,7 @@ def test_figure_with_caption(tmp_path) -> None:
"![[images/antenna.png]]\n\nРисунок 1 — Антенна\n\n" "![[images/antenna.png]]\n\nРисунок 1 — Антенна\n\n"
"Данная антенна используется для ...\n" "Данная антенна используется для ...\n"
) )
assert "\\begin{figure}[ht]" in tex assert "\\begin{figure}[htb]" in tex
assert "\\centering" in tex assert "\\centering" in tex
assert ( assert (
"\\includegraphics[width=0.8\\textwidth]{\\detokenize{images/antenna.png}}" "\\includegraphics[width=0.8\\textwidth]{\\detokenize{images/antenna.png}}"
@@ -60,7 +60,7 @@ def test_figure_with_caption(tmp_path) -> None:
def test_figure_without_caption() -> None: def test_figure_without_caption() -> None:
tex = render("![[images/photo.png]]\n\nОбычный абзац после картинки.\n") tex = render("![[images/photo.png]]\n\nОбычный абзац после картинки.\n")
assert "\\begin{figure}[ht]" in tex assert "\\begin{figure}[htb]" in tex
assert "\\caption{" not in tex assert "\\caption{" not in tex
assert "Обычный абзац после картинки." in tex assert "Обычный абзац после картинки." in tex
@@ -127,7 +127,7 @@ TABLE_MD = (
def test_table_with_caption() -> None: def test_table_with_caption() -> None:
tex = render(TABLE_MD) tex = render(TABLE_MD)
assert "\\begin{table}[ht]" in tex assert "\\begin{table}[htb]" in tex
assert "\\caption{Сравнение скорости}" in tex assert "\\caption{Сравнение скорости}" in tex
assert "\\begin{tabularx}{\\textwidth}" in tex assert "\\begin{tabularx}{\\textwidth}" in tex
assert "\\textbf{1} & 0.027852 & 0.000285 \\\\" in tex assert "\\textbf{1} & 0.027852 & 0.000285 \\\\" in tex