如何使独立 tikz 图形的标题居中而忽略文本节点?

如何使独立 tikz 图形的标题居中而忽略文本节点?

我最近问过这个问题并在几分钟内获得了有效答案。不幸的是,由于我提供的 MWE 过于简单(我的错,抱歉),我得到的答案不适用于我的真实案例。我有一个独立的图,我将其代码复制如下作为 MWE:

\documentclass[border={45 0 0 0}]{standalone}

% PACKAGES LOADING

\usepackage{units} % To specify units when computing
\usepackage{tikz} % To plot almost everything.
\usepackage{pst-3d, tikz-3dplot} % To draw in 3D.

% FIGURE ITSELF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{tikzpicture}
\draw (0,0) node[anchor=east]{$(0,0,1)$} -- (5,0) node[anchor=west]{$(1,0,0)$} -- (2.5,5) node[anchor=south]{$(0,1,0)$} -- cycle;
\useasboundingbox (current bounding box);
\coordinate (a) at (0,0);
\coordinate (b) at (5,0);
\coordinate (c) at (2.5,5);
\coordinate (d) at ($(b)!0.5!(c)$);
\coordinate (e) at ($(a)!1/3!(d)$);
\coordinate (f) at ($(a)!2/3!(d)$);
\node [right] () at (d) {$L_1=(\nicefrac{1}{2},\nicefrac{1}{2},0)$};
\node [below right] () at (e) {$L_2=(\nicefrac{1}{6},\nicefrac{1}{6},\nicefrac{2}{3})$};
\node [above left] () at (f) {$L=(L_1,L_2;\nicefrac{1}{2},\nicefrac{1}{2})=(\nicefrac{1}{3},\nicefrac{1}{3},\nicefrac{1}{3})$};
\filldraw [] (d) circle (1pt);
\filldraw [] (e) circle (1pt);
\filldraw [] (f) circle (1pt);
\draw[densely dotted] (a) -- (d);
\end{tikzpicture}

\end{document}

然后,我将这个独立的图形包含到更大的文档中,使用以下代码:

\documentclass{article}

% PACKAGES LOADING

\usepackage{graphicx}

% DOCUMENT ITSELF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{figure}
\centering
\includegraphics[]{MWE_1.pdf}
\caption{Caption}
\end{figure}

\end{document}

我问的问题,我得到了一个答案,use as bounding box当图形在.tex主文档本身的文件中编译时,该答案有效。但是,由于我在文档中编译了图形standalone并通过 将其包含在主文档中includegraphics[]{},因此我需要增加文档的左侧边框standalone以使其完全适合内部。然后,当我通过 将此图形放入主文档时includegraphics[]{},标题不再按预期相对于三角形居中(它相对于整个图形居中)。请参阅下面的输出:

在此处输入图片描述

我该怎么做才能使standalone图形标题相对于主.tex文档中的三角形居中?

答案1

图片标题位于图片中央,图像本身看起来“偏离中心”(见答案底部); 的定义L远远突出于三角形的左侧,并且没有任何东西可以增加右侧图像的大小。 如果要将标题置于三角形的中心,您可以制作一个框作为最小画布尺寸,并将其用作边界框\path [use as bounding box] (0,0) rectangle (WIDTH,HEIGHT);

\documentclass[border={45 0 0 0}]{standalone}

% PACKAGES LOADING

\usepackage{units} % To specify units when computing
\usepackage{tikz} % To plot almost everything.
\usepackage{pst-3d, tikz-3dplot} % To draw in 3D.

% FIGURE ITSELF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{tikzpicture}
  \draw (0,0) node[anchor=east]{$(0,0,1)$} -- (5,0) node[anchor=west]{$(1,0,0)$} -- 
  (2.5,5) node[anchor=south]{$(0,1,0)$} -- cycle;
%% --- Code changes begin here ---
  % \useasboundingbox (current bounding box);
  \path [use as bounding box] (0,0) rectangle (8cm,0cm);
%% --- Code changes end here ---
  \coordinate (a) at (0,0);
  \coordinate (b) at (5,0);
  \coordinate (c) at (2.5,5);
  \coordinate (d) at ($(b)!0.5!(c)$);
  \coordinate (e) at ($(a)!1/3!(d)$);
  \coordinate (f) at ($(a)!2/3!(d)$);
  \node [right] () at (d) {$L_1=(\nicefrac{1}{2},\nicefrac{1}{2},0)$};
  \node [below right] () at (e) {$L_2=(\nicefrac{1}{6},\nicefrac{1}{6},\nicefrac{2} 
  {3})$};
  \node [above left] () at (f) {$L=(L_1,L_2;\nicefrac{1}{2},\nicefrac{1}{2})= 
  (\nicefrac{1}{3},\nicefrac{1}{3},\nicefrac{1}{3})$};
  \filldraw [] (d) circle (1pt);
  \filldraw [] (e) circle (1pt);
  \filldraw [] (f) circle (1pt);
  \draw[densely dotted] (a) -- (d);
\end{tikzpicture}

\end{document}

偏离中心的三角形:

偏心三角形

中心三角形:

中心三角形

相关内容