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?

1

2 Answers 2

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}
4
  • Shouldn't \center be \centering? Commented Nov 15, 2014 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) Commented Nov 15, 2014 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. Commented Nov 6, 2015 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... Commented Dec 15, 2021 at 6: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

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.