![如何绘制具有文本宽度但在页边距上只有单个节点的 tikzpicture?](https://linux22.com/image/340607/%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E5%85%B7%E6%9C%89%E6%96%87%E6%9C%AC%E5%AE%BD%E5%BA%A6%E4%BD%86%E5%9C%A8%E9%A1%B5%E8%BE%B9%E8%B7%9D%E4%B8%8A%E5%8F%AA%E6%9C%89%E5%8D%95%E4%B8%AA%E8%8A%82%E7%82%B9%E7%9A%84%20tikzpicture%EF%BC%9F.png)
我想绘制一张完全适合文本宽度的 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}