0

I recently asked this question and obtained a valid answer within minutes. Unfortunately, due to oversimplification in the MWE I provided (my bad, sorry), the answer I got does not work for my real case scenario. I have a standalone figure, the code of which I copy below as a 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}

I then include this standalone figure into a larger document, with the following code:

\documentclass{article}

% PACKAGES LOADING

\usepackage{graphicx}

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

\begin{document}

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

\end{document}

In the question I asked, I obtained an answer with use as bounding box that works when the figure is compiled in the .tex file of the main document itself. However, since I compile the figure in a standalone document and include it in the main one via includegraphics[]{}, I need to increase the left-hand side border of the standalone document to make it fully fit inside. Then, when I put this figure in the main document via includegraphics[]{}, the caption is no longer centered as desired with respect to the triangle (it is centered with respect to the entire figure). See output below:

enter image description here

What can I do to get the standalone figure's caption centered with respect to the triangle in the main .tex document?

2
  • What do they do? Why in particular would you use them for, if I may ask?
    – EoDmnFOr3q
    Commented Feb 23, 2021 at 14:05
  • 1
    Never mind. the caption isn't added until after. But they basically put the contents into a minipage and adjust the width acordingly. Commented Feb 23, 2021 at 14:06

1 Answer 1

1

The caption is centered on the image, it's the image itself that seems "off centre" (see bottom of answer); the definition of L sticks out far to the left of the triangle and there is nothing to increase the size of the image to the right. If you want to center the caption on the triangle you can make a box that will act as the minimum canvas size and use it as the bounding box with \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}

Off centre triangle:

off centre triangle

Centred triangle:

centred triangle

2
  • How did you figure out that 8cm is the correct width?
    – EoDmnFOr3q
    Commented Feb 23, 2021 at 15:15
  • 1
    It was the first number I put it and it looked pretty close, but it is not exact. If you want the triangle to be exactly centered you can choose a value larger than the width of your drawing, centre the tikz image, and put the middle of the triangle at 0 on the x axis. Doing this will mean you won't have to measure the length of generated text such as the definition of L, as the chosen bounding box would be larger than the drawn image and will act as a buffer around it.
    – Fergus
    Commented Feb 23, 2021 at 15:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .