我有以下简单的tikz
图片。参见MWE:
\documentclass{article}
% 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{figure}
\centering
\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;
\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}
\medbreak
\caption{Simplex}\label{f1.1}
\end{figure}
\end{document}
从下面的输出中可以看出,标题相对于整个图形居中,但我想让它仅相对于三角形居中(即忽略文本)。我见过类似的答案,它们可以use as bounding box
实现我想要的效果,但我无法成功使用它。我应该如何实现我想要的效果?
谢谢你们!
答案1
\documentclass{article}
% 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{figure}
\centering
\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}
\medbreak
\caption{Simplex}\label{f1.1}
\end{figure}
\end{document}
A
答案2
另一种方法是在末尾添加空白,使宽度相对于中心对称(2.5,2.5)。减小边界框可能会出现重叠的问题。
\documentclass{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.
\usepackage{caption}
\usetikzlibrary{calc}
% FIGURE ITSELF %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\sbox0{\begin{tikzpicture}% measure width
\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;
\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);
\path ($(current bounding box.west)!2!(2.5,2.5)$);% add white space relative to center
\end{tikzpicture}}%
\begin{minipage}{\wd0}
\usebox0
\medbreak
\captionof{figure}{Simplex}\label{f1.1}
\end{minipage}
\end{document}