在 .TEX documentclass{standalone} 中为 TIKZ 图添加标题或标题

在 .TEX documentclass{standalone} 中为 TIKZ 图添加标题或标题

我已将 VSCode 生成的图表导出为.tex文件。现在我想在图表顶部添加标题或说明。我不确定该怎么做!欢迎提出任何建议!谢谢。代码如下所示:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

     
{LONG Plotting CODE}

\end{tikzpicture}

\end{document}

答案1

您可以使用节点的锚点current bounding box:尝试锚点、、、、.north等。.west.north east.120

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[blue,nodes={black}]
(0,0)  coordinate (A) node[below left] {$A$}--
(5,0)   coordinate (B) node[below right]{$B$}--
(1,3.5) coordinate (C) node[above]      {$C$}--cycle;

\path (current bounding box.south) node[below]{This is a triangle};
\end{tikzpicture}
\end{document}

如果存在多个子块,则local bounding box可能会有帮助。

在此处输入图片描述

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.8]
\begin{scope}[local bounding box=L,shift={(-6,0)}]
\draw[blue,fill=blue!20]
(0,0)--(5,0)--(1.2,3.8)--cycle;
\end{scope}

\begin{scope}[local bounding box=C]
\draw[magenta,fill=magenta!30]
(0,0) node[shift={(30:.8)}]{$60^{\circ}$}--
(4,0) node[shift={(150:.8)}]{$60^{\circ}$}--
([turn]120:4)--cycle;
\end{scope}

\begin{scope}[local bounding box=R,shift={(6,0)}]
\draw[cyan,fill=cyan!20]
(0,0)--(4,0)--(0,3)--cycle;
\draw[cyan] (0,0) rectangle +(.5,.5);
\end{scope}

\path (L.south) node[below=5mm]{A triangle};
\path (C.south) node[below=5mm]{An equilateral triangle};
\path (R.south) node[below=5mm]{A right triangle};
\end{tikzpicture}
\end{document} 

相关内容