8

I have a TikZ picture which I want to include as a centered figure in my LaTeX document. However, the "centering" I am trying to achieve is somewhat special and best explained by the image below:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \centering
  \begin{tikzpicture}
    \draw[fill] (0,0) circle [radius=0.075] node [inner sep=0pt] (c) {};
    \draw [red] (c) edge [bend right] node[at end, right]{this is the center} (5,-1);
  \end{tikzpicture}
  \caption{}
\end{figure}
\end{document}

resulting in img

How can I make the picture to be centered around the "center"-dot, e.g. by specifying the node (c) which is to be put in the horizontal middle of the page?

Tobi
  • 56,353
Bernd
  • 1,785

2 Answers2

9

enter image description here

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \centering
  \begin{tikzpicture}
    \draw[fill,use as bounding box] (0,0) circle [radius=0.075] node [inner sep=0pt] (c) {};
    \draw [red] (c) edge [bend right] node[at end, right]{this is the center} (5,-1);
  \end{tikzpicture}

\vspace{1cm}
  \caption{}
\end{figure}
\end{document}
David Carlisle
  • 757,742
  • Shouldn't \center be \centering? – Tobi Nov 15 '14 at 10:23
  • @Tobi oops yes fixed thanks (it works actually, but it's bad style:-) (It was just copied from the question, I didn't spot it) – David Carlisle Nov 15 '14 at 10:27
  • Thanks, that was quite useful for me in the context of beamer, where you want a horizontal centering of the elements in the first overlay. If one doesn't want to bother about the vertical positioning, just use e.g. \draw[white,use as bounding box] (0,0) circle [radius=0.075] {}; as the first command to set the centering, and [t] option for frame to have the tikzpicture aligned to the top vertically. – Joce Nov 06 '15 at 16:45
  • This has the drawback of setting picture width to 0. Would it be possible to enlarge the bounding box instead of reducingi it? I'm thinking of something like creating an empty node whose x coordinate is the reverse of the one from current bounding box.south east... – JeanPierre Dec 15 '21 at 06:17
6

Although use as bounding box plus \vspace would probably be my first or "default" choice for this kind of thing, in this case you could try the trim right key which would make the \vspace unnecessary.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}
  \centering
  \begin{tikzpicture}[trim right=(c)]
    \draw[fill] (0,0) circle [radius=0.075] node [inner sep=0pt] (c) {};
    \draw [red] (c) edge [bend right] node[at end, right]{this is the center} (5,-1);

  \end{tikzpicture}
  \caption{}
\end{figure}
\end{document}

enter image description here

David Carlisle
  • 757,742
Mark Wibrow
  • 70,437