我有一张图表和下面的一些文本。如何才能仅获取红色框作为输出?
\useasboundingbox (Graph.north west) rectangle (Text.south east);
不起作用。
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[]
\begin{scope}[local bounding box=Graph]
\draw[] (0,0) rectangle (4,2);
\end{scope}
\draw[] (1,0) -- (4,4);
\begin{scope}[local bounding box=Text]
\node[shift={(Graph.south west)}, anchor=north west, text width=4cm]{Some text here.};
\end{scope}
\draw[red] (Graph.north west) rectangle (Text.south east);
% \clip[] (Graph.north west) rectangle (Text.south east);
\useasboundingbox (Graph.north west) rectangle (Text.south east);
\end{tikzpicture}
\end{document}
答案1
不必先画对角线,最后再画就可以了。然后按照你的想法剪下矩形\clip
。
\documentclass[margin=5pt, tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[]
\begin{scope}[local bounding box=Graph]
\draw[blue] (0,0) rectangle (4,2);
\end{scope}
\begin{scope}[local bounding box=Text]
\node[shift={(Graph.south west)}, anchor=north west, text width=4cm]{Some text here.};
\end{scope}
\draw[red] (Graph.north west) rectangle (Text.south east);
\clip[] (Graph.north west) rectangle (Text.south east);
%\useasboundingbox (Graph.north west) rectangle (Text.south east);
\draw[] (1,0) -- (4,4);
\end{tikzpicture}
\end{document}