tcbox
我正在尝试用包装项目填充页面的剩余空间includesvg
。当我这样做时,会出现奇怪的行为。当包含一个高 svg 时,它不会填满图像的整个宽度,它的间距行为很奇怪。有时它会与文本重叠,有时它会适合,但它似乎从来没有与最后一段下方的 parskip 有适当的垂直间距。当我使用宽图像时,它会在调整大小以填充其余垂直空间之前填充文本的宽度,它总是会渗入右边距。
所以我最终有两个问题
- 我认为右边距的出血是由于
tcbox
默认填充造成的。我想要那个填充,那么我该如何在那个宏中适应它呢? - 如何修复垂直填充以在所有情况下都有适当的间距?
这是包含三个文件的 MWE。
主文本
\documentclass{book}
\usepackage{lipsum}
\usepackage{svg}
\usepackage{tcolorbox}
\usepackage{zref-savepos}
\newcommand{\filltopageendsvg}[2][]{%
\par
\zsaveposy{top-\thepage}% Mark (baseline of) top of image
\vfill
\zsaveposy{bottom-\thepage}% Mark (baseline of) bottom of image
\begin{center}
\smash{%
\tcbox[colframe=black]{%
\includesvg[height=\dimexpr\zposy{top-\thepage}sp-\zposy{bottom-\thepage}sp\relax,#1]{#2}%
}
}%
\end{center}
\par
}
\begin{document}
\chapter{The First Chapter}
\lipsum[1]
\filltopageendsvg[width=\textwidth]{tall.svg}
\newpage
\lipsum[1]
\chapter{The Second Chapter}
\lipsum[1]
\filltopageendsvg[width=\textwidth]{wide.svg}
\end{document}
高.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="60.288326mm"
height="74.001808mm"
viewBox="0 0 60.288326 74.001808"
version="1.1"
id="svg5"
sodipodi:docname="tall.svg"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.2516522"
inkscape:cx="51.531887"
inkscape:cy="152.5983"
inkscape:window-width="2560"
inkscape:window-height="1007"
inkscape:window-x="0"
inkscape:window-y="1168"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-50.232845,-69.50075)">
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:center;text-anchor:middle;stroke-width:0.264583"
x="79.86335"
y="71.507179"
id="text2168"><tspan
sodipodi:role="line"
id="tspan2166"
style="text-align:center;text-anchor:middle;stroke-width:0.264583"
x="79.86335"
y="71.507179">Top</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:center;text-anchor:middle;stroke-width:0.264583"
x="79.869553"
y="143.47362"
id="text3612"><tspan
sodipodi:role="line"
id="tspan3610"
style="text-align:center;text-anchor:middle;stroke-width:0.264583"
x="79.869553"
y="143.47362">Bottom</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:start;text-anchor:start;stroke-width:0.264583"
x="50.121223"
y="107.71261"
id="text3718"><tspan
sodipodi:role="line"
id="tspan3716"
style="text-align:start;text-anchor:start;stroke-width:0.264583"
x="50.121223"
y="107.71261">Left</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:start;text-anchor:start;stroke-width:0.264583"
x="103.42839"
y="107.41151"
id="text6148"><tspan
sodipodi:role="line"
id="tspan6146"
style="text-align:start;text-anchor:start;stroke-width:0.264583"
x="103.42839"
y="107.41151">Right</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:center;text-anchor:middle;stroke-width:0.264583"
x="79.85508"
y="107.71261"
id="text7480"><tspan
sodipodi:role="line"
id="tspan7478"
style="text-align:center;text-anchor:middle;stroke-width:0.264583"
x="79.85508"
y="107.71261">Tall</tspan></text>
</g>
</svg>
宽.svg
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="85.159164mm"
height="36.117317mm"
viewBox="0 0 85.159164 36.117317"
version="1.1"
id="svg5"
sodipodi:docname="wide.svg"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview7"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.2516522"
inkscape:cx="117.84424"
inkscape:cy="56.725023"
inkscape:window-width="2560"
inkscape:window-height="1007"
inkscape:window-x="0"
inkscape:window-y="1168"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" />
<defs
id="defs2" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-50.232845,-89.891085)">
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:center;text-anchor:middle;stroke-width:0.264583"
x="92.298759"
y="91.897514"
id="text2168"><tspan
sodipodi:role="line"
id="tspan2166"
style="text-align:center;text-anchor:middle;stroke-width:0.264583"
x="92.298759"
y="91.897514">Top</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:center;text-anchor:middle;stroke-width:0.264583"
x="92.304962"
y="125.97946"
id="text3612"><tspan
sodipodi:role="line"
id="tspan3610"
style="text-align:center;text-anchor:middle;stroke-width:0.264583"
x="92.304962"
y="125.97946">Bottom</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:start;text-anchor:start;stroke-width:0.264583"
x="50.121223"
y="109.16071"
id="text3718"><tspan
sodipodi:role="line"
id="tspan3716"
style="text-align:start;text-anchor:start;stroke-width:0.264583"
x="50.121223"
y="109.16071">Left</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:start;text-anchor:start;stroke-width:0.264583"
x="128.29922"
y="108.8596"
id="text6148"><tspan
sodipodi:role="line"
id="tspan6146"
style="text-align:start;text-anchor:start;stroke-width:0.264583"
x="128.29922"
y="108.8596">Right</tspan></text>
<text
xml:space="preserve"
style="font-size:2.82223px;line-height:1.25;font-family:'Roboto Slab';-inkscape-font-specification:'Roboto Slab';text-align:center;text-anchor:middle;stroke-width:0.264583"
x="92.315987"
y="109.14623"
id="text7480"><tspan
sodipodi:role="line"
id="tspan7478"
style="text-align:center;text-anchor:middle;stroke-width:0.264583"
x="92.315987"
y="109.14623">Wide</tspan></text>
</g>
</svg>
有点相关,但有所扩展这个问题。
答案1
虽然我还没有回答我最初的问题,但我发现了一个更好的解决方案。在浏览 tcolorbox 文档时,我找到了选项fill height
和公开的属性\tcbtextheight
。结合这些,以下解决方案更加简洁,并实现了我想要的输出...
\documentclass[draft]{book}
\usepackage{lipsum}
\usepackage{svg}
\usepackage{tcolorbox}
\usepackage{zref-savepos}
\usepackage{showframe}
\tcbuselibrary{breakable}
\begin{document}
\chapter{The First Chapter}
\lipsum[1]
\begin{tcolorbox}[height fill]
\centering
\includesvg[height=\tcbtextheight,width=\linewidth]{tall.svg}
\end{tcolorbox}
\clearpage
\chapter{The Second Chapter}
\lipsum[1]
\begin{tcolorbox}[height fill]
\centering
\includesvg[height=\tcbtextheight,width=\linewidth]{wide.svg}
\end{tcolorbox}
\end{document}