我想绘制一张完全适合文本宽度的 tikz 图片,只需使用\textwidth
图片内所有 x 尺寸的倍数即可实现。
但是,有些节点我想放在页边距上。最好在同一个 tikzpicture 内(但不一定)。什么是恰当的怎么做呢?
我知道我可以通过缩放 tikzpicture 并随后调整框的大小来解决这个问题,直到它适合为止,但这种解决方案感觉不对。我更多地考虑使用节点的解决方案,这些节点不用于确定 tikzpicture 的总宽度。
平均能量损失
\documentclass{beamer}
\usepackage{tikz}
\usepackage{kantlipsum}
\begin{document}
\begin{frame}
\kant[9]
\def\rh{1cm}
\def\rw{\textwidth}
\begin{tikzpicture}
\node[ minimum width = \rw, minimum height = \rh,
draw = blue, thick,
fill opacity = 0.3, text opacity = 1,
align = center] (A1) at (0,0) {Block with text width};
\end{tikzpicture}
\begin{tikzpicture}
\node[ minimum width = \rw, minimum height = \rh,
draw = blue, thick,
fill opacity = 0.3, text opacity = 1,
align = center] (A2) at (0,0) {Block with text width};
\node[circle,left] at (A1.west) {A};
\node[circle,right] at (A2.east) {B};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
我不知道什么是正确的,但你可以\useasboundingbox
在边距中添加元素之前使用如下方法。这样当 LaTeX 放置 时,它们将不会被考虑tikzpicture
。
\documentclass{beamer}
\usepackage{tikz}
\usepackage{kantlipsum}
\begin{document}
\begin{frame}
\kant[9]
\def\rh{1cm}
\def\rw{\textwidth}
\begin{tikzpicture}
\node[ minimum width = \rw, minimum height = \rh,
draw = blue, thick,
fill opacity = 0.3, text opacity = 1,
align = center] (A1) at (0,0) {Block with text width};
\end{tikzpicture}
\begin{tikzpicture}
\node[ minimum width = \rw, minimum height = \rh,
draw = blue, thick,
fill opacity = 0.3, text opacity = 1,
align = center] (A2) at (0,0) {Block with text width};
% everything after this is in the margins
\useasboundingbox (current bounding box.south east) rectangle (current bounding box.north west);
\node[circle,left] at (A1.west) {A};
\node[circle,right] at (A2.east) {B};
\end{tikzpicture}
\end{frame}
\end{document}