我目前正在为一个会议准备海报,并决定为此使用“beamerposter”。
因为我不太喜欢标准模板,所以我决定采用类似这样的设计: http://ai.stanford.edu/~tadayuki/poster/poster-sample.pdf
(不幸的是,我不能直接使用该模板,因为我在使用自己的 TikZ 图形时遇到了一些问题。)
这是我的代码的一个简短示例:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[orientation=portrait,size=a0,scale=1.4,debug]{beamerposter}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage{xparse}
\usepackage{blindtext}
\usetikzlibrary{positioning}
\xdefinecolor{topcolor}{rgb}{0.2, 0.4, 0.6}
\xdefinecolor{bottomcolor}{rgb}{1, 0.99, 0.82}
\xdefinecolor{blocktitleboxcolor}{rgb}{0.15, 0.30, 0.60}
\xdefinecolor{blocktitletextcolor}{rgb}{1.00, 1.00, 1.00}
\beamertemplateshadingbackground{bottomcolor}{topcolor}
% The interesting stuff starts here
\newsavebox\blockbox
\NewDocumentEnvironment{myblock}{+m}{%
\vskip 0.5em
\begin{lrbox}{\blockbox}%
\begin{minipage}{1.00\textwidth}
}{
\end{minipage}
\end{lrbox}
\begin{tikzpicture}[node distance=-0.5em]
\node[
fill=white,
draw=black,
line width=4pt,
inner sep=1cm,
rounded corners=1cm,
text width=\textwidth-2cm, % This does not work as expected
outer sep=0pt
](textnode){\usebox\blockbox};
\node[anchor=north,
above=of textnode,
draw=black,
fill=blocktitleboxcolor,
text=blocktitletextcolor,
rounded corners=.5cm,
line width=4pt,
inner xsep=0.8cm,
inner ysep=0.4cm] {\textit{\textsf{\textbf{#1}}}};
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\begin{columns}[T]
\begin{column}{0.40\textwidth}
\rule{\textwidth}{0.5cm}
\begin{myblock}{Foo}
\blindtext
\end{myblock}
\end{column}
\begin{column}{0.40\textwidth}
\rule{\textwidth}{0.5cm}
\begin{myblock}{Foo}
\blindtext
\end{myblock}
\end{column}
\end{columns}
\end{frame}
\end{document}
但是,我希望 TikZ 节点的总宽度为\textwidth
(由水平规则表示)。
不幸的是,我无法在节点上使用“文本宽度”属性。问题似乎是存储在的文本
\blockbox
的宽度为\textwidth
。
有没有办法重新设置盒子的宽度?
由于我对 TeX 内部结构不是很熟悉,可能有更好的方法来实现我想要的效果,所以请随时提出更好的方法......
答案1
设置框时需要考虑框架填充:
\usepackage{calc}
然后你可以去:
\begin{lrbox}{\blockbox}%
\begin{minipage}{\textwidth - 2cm}
答案2
TikZ 将节点内容读取为框,而不是宏参数,因此您可以替换\node {..}
并将\node \bgroup .. \egroup
两个部分放在环境的开始和结束部分。这样就无需将内容存储到框中,也无需解决相关问题。
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[orientation=portrait,size=a0,scale=1.4,debug]{beamerposter}
\usepackage{tikz}
\usepackage[english]{babel}
\usepackage{xparse}
\usepackage{blindtext}
\usetikzlibrary{positioning}
\xdefinecolor{topcolor}{rgb}{0.2, 0.4, 0.6}
\xdefinecolor{bottomcolor}{rgb}{1, 0.99, 0.82}
\xdefinecolor{blocktitleboxcolor}{rgb}{0.15, 0.30, 0.60}
\xdefinecolor{blocktitletextcolor}{rgb}{1.00, 1.00, 1.00}
\beamertemplateshadingbackground{bottomcolor}{topcolor}
% The interesting stuff starts here
\NewDocumentEnvironment{myblock}{+m}{%
\vskip 0.5em
\begin{tikzpicture}[node distance=-0.5em]
\node[
fill=white,
draw=black,
line width=4pt,
inner sep=1cm,
rounded corners=1cm,
text width=\textwidth-2cm, % This does work as expected now
outer sep=0pt
](textnode)
\bgroup
}{%
\egroup;
\node[anchor=north,
above=of textnode,
draw=black,
fill=blocktitleboxcolor,
text=blocktitletextcolor,
rounded corners=.5cm,
line width=4pt,
inner xsep=0.8cm,
inner ysep=0.4cm] {\textit{\textsf{\textbf{#1}}}};
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\begin{columns}[T]
\begin{column}{0.40\textwidth}
\rule{\textwidth}{0.5cm}
\begin{myblock}{Foo}
\blindtext
\end{myblock}
\end{column}
\begin{column}{0.40\textwidth}
\rule{\textwidth}{0.5cm}
\begin{myblock}{Foo}
\blindtext
\end{myblock}
\end{column}
\end{columns}
\end{frame}
\end{document}