另请参阅这。
我将整个文档排版在一个单独的 中tikzpicture
,这意味着文档中的文本块由 表示\path node{...};
。但是,如果不使用额外的tikzpicture
环境,当必须将图形插入文档时,情况会变得复杂。tikzpicture
但是,使用额外的 会产生难以处理的垂直间距(并且会破坏框架框,即background rectange
周围tikzpiture
)。我该如何解决这个问题?我们能否以某种方式使用范围并为其分配样式,以便它可以“模仿” tikzpicture
?我需要能够轻松定位和缩放整个绘图,而不是单独处理绘图的每个路径(以将其调整为上面的文本)。它还会造成将文本定位在绘图之后的问题,因为文本需要与某个东西对齐:您不能将节点与非节点的路径对齐,并且绘图主要由非节点的路径组成(将文本定位到绘图的容器中会很容易,但没有这样的容器)。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\path node[anchor=north west,text width=50mm](n1){This is sentence 1. This is sentence 2. This is sentence 3.};
\path node[anchor=north west,text width=50mm]at(n1.south west){\[2+2=4\]};
% following drawing should behave as a picture
% so that it can be easily moved and scaled
\path node[anchor=north west](t1){DRAWING TITLE};
\path[draw,radius=30pt]($(t1.south)+(0,-30pt)$)circle;
\path[draw,radius=5pt]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
\path[draw,radius=5pt]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
\path[draw,line width=1pt]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
\path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
\path node[font=\tiny]at($(t1.south)+(0,-40pt)$){text};
\end{tikzpicture}
\end{document}
遵循半工作,但输出中未突出显示的其他问题:(1)tikzpicture
由于第二个tikzpicture
环境导致的额外垂直间距(如果所有内容都在单个内,则完全可以控制),(2)varwidth
环境的使用和(结果)节点的剪切(在右侧)。
\documentclass[varwidth=50mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\path node[anchor=north west,text width=50mm](n1){This is sentence 1. This is sentence 2. This is sentence 3.};
\path node[anchor=north west,text width=50mm]at(n1.south west){\[2+2=4\]};
\end{tikzpicture}\par
\begin{tikzpicture}[text width=50mm,align=center]
\path node[anchor=north west](t1){DRAWING TITLE};
\path[draw,radius=30pt]($(t1.south)+(0,-30pt)$)circle;
\path[draw,radius=5pt]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
\path[draw,radius=5pt]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
\path[draw,line width=1pt]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
\path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
\path node[font=\tiny]at($(t1.south)+(0,-40pt)$){text};
\end{tikzpicture}
\end{document}
答案1
您可以使用scope
带有该local bounding box
选项的环境吗?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\path node[anchor=north west,text width=50mm](n1){This is sentence 1. This is sentence 2. This is sentence 3.};
\path node[anchor=north west,text width=50mm]at(n1.south west){\[2+2=4\]};
% following drawing should behave as a picture
% so that it can be easily moved and scaled
\begin{scope}[
shift={(0,-3)},
scale=0.7,
local bounding box=smiley
]
\path node[anchor=north west](t1){DRAWING TITLE};
\path[draw,radius=30pt]($(t1.south)+(0,-30pt)$)circle;
\path[draw,radius=5pt]($(t1.south)+(-15pt,10pt)+(0,-30pt)$)circle;
\path[draw,radius=5pt]($(t1.south)+(15pt,10pt)+(0,-30pt)$)circle;
\path[draw,line width=1pt]($(t1.south)+(0,0)+(0,-30pt)$)--($(t1.south)+(0,10pt)+(0,-30pt)$);
\path[draw]($(t1.south)+(-10pt,-15pt)+(0,-30pt)$)rectangle($(t1.south)+(10pt,-5pt)+(0,-30pt)$);
\path node[font=\tiny]at($(t1.south)+(0,-40pt)$){text};
\end{scope}
\draw [red] (smiley.north west) to[bend left] (smiley.north east);
\node [right] at (smiley.east) {foo};
\end{tikzpicture}
\end{document}