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
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}
3
  • 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) 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 6 '15 at 16:45
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.