我正在使用tikz海报类来创建海报,并有三列几乎延伸到页面底部。我想拉伸中间的空间,blocks
以便每列中最后一个块的底部对齐。如果我要制作另一张海报,其中列的大小不太相似,那么可以修改块的内容以实现相同目的的解决方案将是理想的选择。我知道在 beamerposter 类中这是可能的,但我不想在这个后期阶段切换海报类(而且 tikzposter 有非常好的默认主题)。
由于 tikzposter 使用 tikz 来定位块,而不是使用正常的 LaTeX 定位,因此似乎使用橡胶长度或\vfill
直接使用是不可行的。那么,有没有合理的方法可以做到这一点?我不介意使用 tikzposter 类本身的解决方案,或者必须将内容写入辅助文件。
答案1
我最终自己解决了这个问题。下面是我使用的代码;如果你输入它,myposter.sty
然后使用它\usepackage[colalign]{myposter}
来启用对齐。
它的工作原理是将所有列的自然高度以及有多少块保存到辅助文件中。然后在下一次编译时,对于每一列,它会查看存储的高度和最大存储高度之间的差异,将其除以块数,然后在每个块内(在顶部和底部)添加那么多的填充。
\usepackage{letltxmacro}
\usepackage{ifthen}
\newif\ifmy@colalign
\my@colalignfalse
\DeclareOption{colalign}{
\my@colaligntrue
}
\ProcessOptions\relax
\ifmy@colalign
% Align the bottoms of columns
% Declarations
\newcounter{my@column}
\newcounter{my@column@loop}
\newcounter{my@block}
\newdimen\my@columnextraspace
\newdimen\my@maxcolheight
\newdimen\my@colheight
\newdimen\my@blocktopstart
\newdimen\my@rounded
% Store the natural height and number of blocks of the current column in the aux file
\gdef\my@storecolheight{
\ifnum\value{my@column} > 0 %
\expandafter\newdimen\csname my@colheight\alph{my@column}\endcsname
\expandafter\setlength\csname my@colheight\alph{my@column}\endcsname{\my@colheight}
\immediate\write\@auxout{\noexpand\newlabel{my@colheight\alph{my@column}}{{\the\my@colheight}{}}}
\immediate\write\@auxout{\noexpand\newlabel{my@numblocks\alph{my@column}}{{\the\c@my@block}}}
\fi
}
\LetLtxMacro{\orig@block}{\block}
% Replace the \block command with a version that pads each block by \my@columnextraspace
\renewcommand{\block}[3][]{%
\ifTP@columnEnvironment
\my@blocktopstart=0pt\relax
\advance\my@blocktopstart-\TP@blocktop
\fi
\orig@block[{#1}]{#2}{\vspace*{-0.5\my@columnextraspace}#3\vspace*{-0.5\my@columnextraspace}}
\ifTP@columnEnvironment
% count number of blocks
\stepcounter{my@block}
% keep track of the height of the current column
\advance\my@blocktopstart\TP@blocktop
\advance\my@colheight\my@blocktopstart
% don't add the padding to the height
\advance\my@colheight-\my@columnextraspace
\fi
}
% Store the maximum natural height of any column in the aux file
\gdef\my@storemaxcolheight{
\ifnum\value{my@column} > 0 %
\newdimen\my@maxcolheight
\newdimen\my@colheight@loop
\setcounter{my@column@loop}{0}
\loop\ifnum\value{my@column@loop}<\value{my@column}
\stepcounter{my@column@loop}
\my@colheight@loop\csname my@colheight\alph{my@column@loop}\endcsname
\ifnum\my@colheight@loop<\my@maxcolheight
\my@maxcolheight\my@colheight@loop
\fi
\repeat
\immediate\write\@auxout{\noexpand\newlabel{my@maxcolheight}{{\the\my@maxcolheight}{}}}
\fi
}
% Read the column height information and calculate how much extra space the current column needs per block
\gdef\my@calcextraspace{
\@ifundefined{r@my@maxcolheight}{%
\my@columnextraspace=0pt\relax
}{%
\expandafter\my@maxcolheight\ref{my@maxcolheight}
\expandafter\my@colheight\ref{my@colheight\alph{my@column}}
\setcounter{my@block}{\ref{my@numblocks\alph{my@column}}}
\my@columnextraspace\my@maxcolheight
\advance\my@columnextraspace-\my@colheight
\divide\my@columnextraspace by \value{my@block}
}
}
% Replace \column command by a version which stores the height (of the previous column) and calls \my@calcextraspace
\gdef\column#1{ % #1: relative width
\ifTP@columnEnvironment
\my@storecolheight
\stepcounter{my@column}
\my@calcextraspace
\setcounter{my@block}{0}
\my@blocktopstart0pt
\my@colheight0pt
% Now the normal \column command
\normalsize
\setlength{\TP@blocktop}{\TP@coltop}
\setlength{\TP@colcenter}{\TP@colcenter+0.5\colwidth+\TP@colspace}
\setlength{\colwidth}{#1\TP@visibletextwidth+#1\TP@colspace-\TP@colspace-\blocklinewidth}
\setlength{\TP@colcenter}{\TP@colcenter+0.5\colwidth+\blocklinewidth}
\fi
}
% Replace the columns environment with a version which stores the height of the final column and the max column
\renewenvironment{columns}{
\TP@columnEnvironmenttrue
\setlength{\TP@colcenter}{-0.5\TP@visibletextwidth-\[email protected]\blocklinewidth}
\global\TP@colcenter=\TP@colcenter
\global\TP@coltop=\TP@blocktop
\global\TP@colbottom=\TP@blocktop
\colwidth=0pt
}{
\my@storecolheight
\my@storemaxcolheight
\TP@columnEnvironmentfalse
\global\TP@blocktop=\TP@colbottom
}
\fi