1

Consider two circles with long text nodes inside:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}
    \draw (0,0) circle (1.5cm) node[text width=3cm] {This is a relatively long text};
    \draw (5,0) circle (1.5cm) node[text width=3cm] {This is another very long text};
    \end{tikzpicture}

\end{document}

enter image description here

I want to have the text centered and wrapped in each circle. I've tried two solutions so far:

  1. Using label=center:<my_text> inside node, as suggested here. This centers the text, but does not wrap it. So the text goes outside the circle.

  2. Using pos=0.5 or midway inside node, as suggested here. This works fine for one circle, but not for two. The text is placed on top of each other in the first circle.

How can I achieve what I want?

  • 1
    Just add align=center to the node options. – Alan Munn Nov 13 at 17:37
1

Alignment inside nodes is determined by the align key. In this case you want align=center:

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}
    \draw (0,0) circle (1.5cm) node[text width=3cm,align=center] {This is a relatively long text};
    \draw (5,0) circle (1.5cm) node[text width=3cm,align=center] {This is another very long text};
    \end{tikzpicture}

\end{document}

output of code

1

One approach is to make the node circle shapes, add align=center to the text, and given them a minimum size.

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

    \begin{tikzpicture}
    \draw (0,0)% circle (1.5cm) 
    node[align=center,minimum size=3cm,draw,circle] 
    {This is\\ a relatively\\ long text};
    \draw (5,0)% circle (1.5cm) 
    node[align=center,minimum size=3cm,draw,circle] 
    {This is\\ another very\\ long text};
    \end{tikzpicture}

\end{document}

enter image description here

You need to add the line breaks yourself, or use something like parshape to automatically follow the outline of a circle.

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.