我正在处理的文档生成了非常大的 Tikz 图片(使用 Forest 包),这些图片跨越 PDF 中的多个水平和垂直页面。
这些图片需要有标题、文本、常规 JPG 图像(徽标)和 PST 图片(QR 码)。
使用独立类时,Forest 可以正常生成,但其前面的任何文本/表格都会出现在其左侧。使用varwidth
独立参数,我可以将它们放在 Forest 上方,但它将不再跨越多个页面。
我怎样才能两全其美:将标题放在森林上方,同时让它占用所需的空间?还需要将版权声明放在森林下方。
这肯定与计算有关,\textwidth
但是是什么呢?
\documentclass[varwidth=true,border=10pt]{standalone}
%\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usepackage{adjustbox}
\usepackage{pst-barcode}
\usepackage[crop=off]{auto-pst-pdf}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
\begin{tabular*}{\textwidth}{@{}l @{\extracolsep{\fill}} r@{}}
\begin{tabular}[t]{@{}l@{}}
Title\\ Text
\end{tabular} &
\begin{adjustbox}{valign=t}
\begin{pspicture}(0.7in,0.7in)
\psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{adjustbox}
\end{tabular*}
\begin{forest}
for tree={
draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
},
where n children=0{
child anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
draw=red,for parent={
parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue
}
}{}
}
[Parent,name=Parent
[Child1
[,phantom]
[Child11]
[Child12]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
]
% <===== Insert below snippet with \node here =====
\end{forest}
\begin{tiny}Copyright \textcopyright Myself, 2014\end{tiny}
\end{document}
如果保留 Child1 和 Child3 节点,它将渲染得很好,但包括 Child3 的重复项会剪切森林。
编辑:
我能想到的解决方法之一是将必要的内容包含在\node
森林内部。但是当我尝试将tabular*
环境移动到节点中(如下所示)并移动到上面注释指示的行时,它似乎无法正确计算森林的总宽度:
\node(title) at (0,35ex){
\begin{tabular*}{\textwidth}{@{}l @{\extracolsep{\fill}} r@{}}
\begin{tabular}[t]{@{}l@{}}
Title\\Subtitle\\\begin{tiny}as of June 20, 2014\end{tiny}
\end{tabular} &
\begin{adjustbox}{valign=t}
\begin{pspicture}(0.7in,0.7in)
\psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{adjustbox}
\end{tabular*}
}[];
MWE 的最终结果是经过修剪的森林,其中标题和二维码图片放置正确:
如果tabular*
将文档顶部的环境移至注释行,并varwidth
从文档类中删除选项,则它将如下所示,标题和 QRCode 位于页面中间,而不是分别位于左侧和右侧:
编辑:
尝试执行 Johnsavebox
在评论中的提示,但的内容savebox
与环境并排呈现tabular*
,而不是在环境上方呈现。但它们的宽度相等,这很好。
\documentclass[border=10pt]{standalone}
\begin{document}
\newsavebox{\forestbox}
\sbox{\forestbox}{
oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
}
\newlength{\forestboxlen}
\settowidth{\forestboxlen}{\usebox{\forestbox}}
\begin{tabular*}{\forestboxlen}{@{}l @{\extracolsep{\fill}} r@{}}
\begin{tabular}[t]{@{}l@{}}
Title\\ Text
\end{tabular} &
\begin{adjustbox}{valign=t}
\begin{pspicture}(0.7in,0.7in)
\psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{adjustbox}
\end{tabular*}
\usebox{\forestbox}
\end{document}
答案1
我无法让 pst 内容工作,因此改用图像。我使用 \hfill 将内容对齐到左侧和右侧。您需要一个 minipage 来定义 \textwidth。
\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usepackage{adjustbox}
%\usepackage{pst-barcode}
%\usepackage[crop=off]{auto-pst-pdf}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{mwe}
\newlength{\offset}
\newlength{\boxwidth}
\newsavebox{\mybox}
\setlength{\parindent=0pt}
\begin{document}
\savebox{\mybox}{% need to compute width
\begin{forest}
for tree={
draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
},
where n children=0{
child anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
draw=red,for parent={
parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue
}
}{}
}
[Parent,name=Parent
[Child1
[,phantom]
[Child11]
[Child12]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
]
% <===== Insert below snippet with \node here =====
\end{forest}
}
\settowidth{\boxwidth}{\usebox{\mybox}}
\begin{minipage}{\boxwidth}
\setlength{\offset}{0.6\baselineskip}% distance from top to baseline for parbox
\addtolength{\offset}{-0.7in}% daistance from top to baseline for image
\parbox[t]{0.5\textwidth}{Title\\ Text}
\hfill\raisebox{\offset}{\includegraphics[width=0.7in,height=0.7in]{image}}
%\begin{pspicture}(0.7in,0.7in)
% \psbarcode{http://www.ctan.org}{}{qrcode}
%\end{pspicture}
\usebox{\mybox}
\begin{tiny}Copyright \textcopyright Myself, 2014\end{tiny}
\end{minipage}
\end{document}
答案2
似乎将所有内容都放入表格环境中可以一次性解决所有问题!最终版本需要在中间添加徽标,在底部添加版权,但一般来说,这应该可行:
\documentclass[border=10pt]{standalone}
%\documentclass[border=10pt]{standalone}
\usepackage{forest}
\usepackage{adjustbox}
\usepackage{pst-barcode}
\usepackage[crop=off]{auto-pst-pdf}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\begin{document}
\begin{tabular}{l r}
\begin{tabular}[t]{@{}l@{}}
Title\\
Text\\
\end{tabular} &
\begin{adjustbox}{valign=t}
\begin{pspicture}(0.7in,0.7in)
\psbarcode{http://www.ctan.org}{}{qrcode}
\end{pspicture}
\end{adjustbox} \\
\multicolumn{2}{c}{
\begin{forest}
for tree={
draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
node options={font=\footnotesize, minimum width=14em, minimum height=10ex, rounded corners=1ex},
edge path={
\noexpand\path[\forestoption{edge}]
(!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
},
where n children=0{
child anchor=west,
edge path={
\noexpand\path[\forestoption{edge}]
([xshift=-6em]!u.parent anchor) |- (.child anchor)\forestoption{edge label};
},
draw=red,for parent={
parent anchor=south, l sep=-12em, grow'=east, calign=child edge, draw=blue
}
}{}
}
[Parent,name=Parent
[Child1
[,phantom]
[Child11]
[Child12]
]
[Child3
[,phantom]
[Child31]
[Child32]
]
[Child4
[,phantom]
[Child41]
[Child42]
]
]
\end{forest}
}
\end{tabular}
\end{document}