Graphics, Figures & TablesVertical Text Alignment in circled Nodes

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Vertical Text Alignment in circled Nodes

Post by SAKDOSS »

Hello,

It seems that I have a lot of questions these days.

I am drawing two ellipses and two circles with tikZ:

Code: Select all

\begin{tikzpicture}
  \node[ellipse, draw] at (0,0) {
    \begin{tikzpicture}
      \node at (0,0.2){$blablabla$};
      \node at (0,-0.2){$b$};
    \end{tikzpicture}
  };

  \node[ellipse, draw] at (3.5,0) {
    \begin{tikzpicture}
      \node at (0,0.2){$b$};
      \node at (0,-0.2){$blablabla$};
    \end{tikzpicture}
  };

  \node[circle, draw] at (0,3.5) {
    \begin{tikzpicture}
      \node at (0,0.2){$blablabla$};
      \node at (0,-0.2){$b$};
    \end{tikzpicture}
  };

  \node[circle, draw] at (3.5,3.5) {
    \begin{tikzpicture}
      \node at (0,0.2){$b$};
      \node at (0,-0.2){$blablabla$};
    \end{tikzpicture}
  };
\end{tikzpicture}
The result is here:
tikZ-text-alignment.png
tikZ-text-alignment.png (19.34 KiB) Viewed 8771 times
As you can see the texts in the two ellipses are centered vertically whereas they are not in the circles. This is due to the fact that "blablabla" is longer than "b" but I don't understand why it's working for the ellipses only.

Is it possible to center vertically the texts in the circles without changing the coordinates of the nodes ?
Last edited by localghost on Sat Feb 23, 2013 7:25 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Vertical Text Alignment in circled Nodes

Post by SAKDOSS »

Again I found the solution (sorry for posting). I give the answer it may help someone:

Code: Select all

\node (a) at (6,0.2){$b$};
\node (b) at (6,-0.2){$blablabla$};
\node[draw, circle, fit=(a) (b)] {};
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Vertical Text Alignment in circled Nodes

Post by localghost »

Thanks for sharing. However, your solution in form of a self-contained and minimal document would be preferable since it would be compilable out of the box for everybody else.


Thorsten
SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Vertical Text Alignment in circled Nodes

Post by SAKDOSS »

Indeed here is a compilable latex file:

Code: Select all

\documentclass{article}

\usepackage[english]{babel}
\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
  \node[ellipse, draw] at (0,0) {
    \begin{tikzpicture}
      \node at (0,0.2){$blablabla$};
      \node at (0,-0.2){$b$};
    \end{tikzpicture}
  };

  \node[ellipse, draw] at (3.5,0) {
    \begin{tikzpicture}
      \node at (0,0.2){$b$};
      \node at (0,-0.2){$blablabla$};
    \end{tikzpicture}
  };

  \node[circle, draw] at (0,3.5) {
    \begin{tikzpicture}
      \node at (0,0.2){$blablabla$};
      \node at (0,-0.2){$b$};
    \end{tikzpicture}
  };

  \node[circle, draw] at (3.5,3.5) {
    \begin{tikzpicture}
      \node at (0,0.2){$b$};
      \node at (0,-0.2){$blablabla$};
    \end{tikzpicture}
  };
\end{tikzpicture}

\begin{tikzpicture}
  \node (a) at (6,0.2){$b$}; \node (b) at (6,-0.2){$itworksperfectly!$};
  \node[draw, circle, fit=(a) (b)] {};
\end{tikzpicture}

\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Re: Vertical Text Alignment in circled Nodes

Post by Stefan Kottwitz »

Thanks for the solution! And in this way, I could click on "Open in writeLaTeX" and immediately test your example, very good.

Stefan
LaTeX.org admin
SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Re: Vertical Text Alignment in circled Nodes

Post by SAKDOSS »

I did not notice. Great feature.
Post Reply