我的意思是,如果我使用例如\blockwidth
设置环境的宽度tikzfigure
,我会得到未定义的控制序列错误。在这种情况下,一种解决方法是使用\linewidth
,但我需要从框的边缘减去间隔距离,而且我也无法访问该间隔。
显然,当为元素定义自定义样式时,尺寸是定义明确的,正如在文档中所读到的。
但是,有没有办法在海报正文中访问它们?
我认为在这种情况下给出 MWE 很困难,而且不相关。尽管如此,我还是给出了。
\documentclass{tikzposter}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\title{Title} \institute{Inst}
\author{Auth} \titlegraphic{Logo}
\usetheme{Basic}
\begin{document}
\maketitle
\block{BlocktitleA}{Blocktext}
\begin{columns}
\column{0.3}
\block{BlocktitleB}{
\newlength{\figw}
\setlength{\figw}{\blockwidth}
\begin{tikzpicture}
\pgfplotsset{
height=0.5*\figw,
width=0.5*\figw,
}
\begin{axis}[
xmin=1.5,
xmax=5
]
\addplot[
solid,
line width=0.8mm,
samples=100,
domain=1.5:5,
restrict y to domain=0.6:2.2
] {0.7+(2.22/x)};
\end{axis}
\end{tikzpicture}
}
\column{0.7}
\block{BlocktitleC}{Blocktext}
\note{Notetext}
\end{columns}
\end{document}
这会导致未定义的控制序列错误和零长度警告。
答案1
在columns
环境中,a 的总宽度\block
为\colwidth
。文本块的宽度为\linewidth
。我相信这两个始终可用。
下面的代码演示了如何定义额外的宏来访问类定义的维度。当然,这不是一个明确的列表,但我想它应该涵盖了大多数情况。
\documentclass[a1paper]{tikzposter}
\usepackage{pgfplots,array}
\usetikzlibrary{calc,arrows.meta}
\title{Title} \institute{Inst}
\author{Auth} \titlegraphic{Logo}
\usetheme{Basic}
% define macros without @
\makeatletter
\newcommand{\blockwidth}{\TP@blockbodywidth}
\newcommand{\blockinnersep}{\TP@blockbodyinnersep}
\newcommand{\innerblockwidth}{\TP@innerblockbodywidth}
\newcommand{\innerblockinnersep}{\TP@innerblockbodyinnersep}
\makeatother
\newcommand\printtable{%
\begin{tabular}{@{}>{\ttfamily\textbackslash}ll}
\multicolumn{2}{l}{Existing macros:} \\
colwidth & \the\colwidth \\
linewidth & \the\linewidth \\[10pt]
\multicolumn{2}{l}{New macros:} \\
blockwidth & \the\blockwidth \\
blockinnersep & \the\blockinnersep \\
innerblockwidth & \the\innerblockwidth \\
innerblockinnersep & \the\innerblockinnersep
\end{tabular}
\bigskip
% demonstrates extent of text block
X\dotfill X}
\newcommand\printdimensions{%
% the background and frame of a block is drawn by a node named blockbody
% use that to draw some lines
\draw
let
\p1=(blockbody.south west),\p2=(blockbody.south east),\n1={scalar(\x2-\x1)}
in
[red,Bar-Bar,ultra thick] (\x1,\y1-4cm) coordinate (a) -- (\x2,\y2-4cm) coordinate (b)
node[midway,above] {$\mathtt{blockwidth} \approx \n1\,\mathrm{pt}$};
\draw [dashed,red] (blockbody.west) -- ([yshift=-1cm]a);
\draw [dashed,red] (blockbody.east) -- ([yshift=-1cm]b);
\draw
let
\p1=(blockbody.south west),\p2=(blockbody.south east),\n1={scalar(\x2-\x1-2*\blockinnersep)}
in
[blue,Bar-Bar,ultra thick] (\x1+\blockinnersep,\y2-2cm) coordinate (a) -- (\x2-\blockinnersep,\y2-2cm) coordinate (b)
node[midway,above] {$\mathtt{linewidth} \approx \n1\,\mathrm{pt}$};
\draw [dashed,blue] ([yshift=6cm]a) -- ([yshift=-1cm]a);
\draw [dashed,blue] ([yshift=6cm]b) -- ([yshift=-1cm]b);
}
\begin{document}
\maketitle
\begin{columns}
\column{0.4}
\block{BlocktitleB}{\printtable}
\printdimensions
\column{0.6}
\block[bodyinnersep=50pt]{BlocktitleC}{\printtable}
\printdimensions
\note{Notetext}
\end{columns}
\block[bodyoffsety=-4cm,titleoffsety=-5cm]{BlocktitleA}{
\printtable
\innerblock{Inner}{\printtable}
}
\printdimensions
\end{document}
答案2
如果在块内使用,\linewidth
则朝向边界的分离已被减去,请参阅以下示例中规则的宽度:
\documentclass{tikzposter}
\usetheme{Basic}
\usepackage{lipsum}
\begin{document}
\block{BlocktitleA}{Blocktext}
\begin{columns}
\column{0.3}
\block{BlocktitleB}{
\newlength{\figw}
\setlength{\figw}{\linewidth}
\rule{\figw}{2pt}
\lipsum
}
\end{columns}
\end{document}
更好的问题是为什么你的 pgf 图比线宽更宽。tikz
会自动在你的图周围放置一些填充,你可以使用它来禁用它inner sep=0pt
。
但是,我会将图做得稍微大一些\linewidth
(约 1%),以便将右轴与周围文本的边框对齐,即使5
x 轴现在稍微突出到边缘。
\documentclass{tikzposter}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetheme{Basic}
\usepackage{lipsum}
\usepackage{printlen}
\usetikzlibrary{backgrounds}
\begin{document}
\block{BlocktitleA}{Blocktext}
\begin{columns}
\column{0.3}
\block{BlocktitleB}{
\lipsum[2]
\begin{tikzpicture}[inner sep=0pt]%
\begin{axis}[%
width=1.01\linewidth,
xmin=1.5,%
xmax=5%,
]%
\addplot[%
solid,%
line width=0.8mm,%
samples=100,%
domain=1.5:5,%
restrict y to domain=0.6:2.2%
] {0.7+(2.22/x)};%
\end{axis}%
\end{tikzpicture}%
}
\end{columns}
\end{document}