我在流程图中使用了我在 Stackexchange 中找到的以下(六边形)循环定义。当其中的文本行数增加时,整个形状的宽度也会增加。我希望形状本身的宽度是固定的。你能帮忙定义这样的六边形吗?它不必遵循我在 MWE 中给出的起始定义。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, shapes.misc, matrix, shapes, arrows, calc, positioning, shapes.geometric, shapes.symbols, shapes.misc, intersections, chains, scopes}
\tikzset{
loop/.style={ % requires library shapes.misc
draw,
chamfered rectangle,
chamfered rectangle xsep=2cm,
text width=10em,
},
}
\begin{document}
\begin{tikzpicture}[node distance=1.6cm]
\node (l1)[loop]{aa};
% node below is wider then the one above. I want the width of the one below to be same as the one above.
\node (l2)[loop,below of=l1]{aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa aaa };
\end{tikzpicture}
\end{document}
答案1
解决方法 A(在定义的样式之外绘图)
我尝试在使用后添加绘图\node
,可以在您的loop
风格之外进行定制。
%! *latex mal-chamfered.tex
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, calc, shapes.misc, matrix, shapes, arrows, calc, positioning, shapes.geometric, shapes.symbols, shapes.misc, intersections, chains, scopes}
\tikzset{
loop/.style={ % requires library shapes.misc
draw,
chamfered rectangle,
%chamfered rectangle ysep=2mm,
chamfered rectangle xsep=10mm,
text width=10em,
align=center,
},
}
\begin{document}
\def\malxsep{3mm}
\begin{tikzpicture}[node distance=1.6cm]
\node (l1)[loop]{aa};
\node (l2)[text width=10em-0.5em, align=center,below of=l1]{aaa aaa aaa \\aaa aaa aaa aaa aaa aaa \\aaa\\ aaa aaa\\ aaa aaa aaa aaa };
\draw (l2.north west)--($(l2.west)+(-\malxsep,0)$)--(l2.south west)--(l2.south east)--($(l2.east)+(\malxsep,0)$)--(l2.north east)--cycle;
\end{tikzpicture}
\end{document}
编辑:解决方法 B(在定义的样式内绘图)
我使用\tikzset
来定义以下内容:我开始修改loop
样式,在表达式中添加append after command
,在部分中合并命令\pgfextra
,最后在 本身中绘制一个六边形\node
。我附上了我的努力成果及其预览。
%! *latex mal-chamfered.tex
\documentclass{article}
\pagestyle{empty}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{
loop/.style={
anchor=north,
text width=10em,
align=center,
append after command={
\pgfextra{
\draw (\tikzlastnode.north west)--($(\tikzlastnode.west)+(-\malxsep,0)$)--
(\tikzlastnode.south west)--(\tikzlastnode.south east)--
($(\tikzlastnode.east)+(\malxsep,0)$)--
(\tikzlastnode.north east)--cycle;
}% End of \pgfextra...
},% End of append after command...
},% End of loop/.style...
}% End of \tikzset...
\begin{document}
\def\malxsep{3mm}
\begin{tikzpicture}[node distance=2cm]
\node(l1)[loop]{aa};
\node(l2)[loop] at (l1.south) {A\\B\\C};
\node(l3)[loop] at (l2.south) {aaa aaa aaa \\aaa aaa aaa aaa aaa aaa \\aaa\\ aaa aaa\\ aaa aaa aaa aaa };
\end{tikzpicture}
\end{document}