Graphics, Figures & TablesVertical Alignment in 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 Alignment in Nodes

Post by SAKDOSS »

Hello,

I am quite new in tikZ and I have two alignment problems with the following code:

Code: Select all

  \begin{tikzpicture}
    % Styles
    \tikzstyle{cluster}=[
      thick,
      densely dashed,
      fill=gray!20,
      ellipse,
      text width=0.3cm,
      text height=0.6cm,
      text centered,
      draw
    ]
    \tikzstyle{arrow}=[->,>=latex]

    % Clusters
    \node[cluster] (c1) at (0,0){$ $};
    \node[cluster] (c2) at (1.6cm,0){$b$};
    
    % Arrow
    \draw[arrow] (c1) to[out=-25, in=-155] (c2) 
       node[midway]{$a$};
  \end{tikzpicture}
It gives the following picture
tikZ-alignment.png
tikZ-alignment.png (5.16 KiB) Viewed 8548 times
I don't understand;
  1. why b is not vertically centered in the ellipse on the right;
  2. why a is not centered on the arrow.
Do you know what is wrong in my code ?

Thanks in advance !

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

alainremillard
Posts: 45
Joined: Fri Mar 16, 2012 8:22 pm

Vertical Alignment in Nodes

Post by alainremillard »

SAKDOSS wrote: 1. why b is not vertically centered in the ellipse on the right;
In your definition of cluster, replace text height=0.6cm with minimum height=1.4cm. The 1.4cm might need some adjustment. With minimum height, you specify the height of the node itself.
SAKDOSS wrote: 2. why a is not centered on the arrow.
If you want to put a node on an arrow, the command must be place between the arrow description and the destination. This should do the trick

Code: Select all

\draw[arrow] (c1) to[out=-25, in=-155] node[midway]{$a$} (c2) ;
Have a nice day
Alain Rémillard
SAKDOSS
Posts: 14
Joined: Thu Feb 21, 2013 5:06 pm

Re: Vertical Alignment in Nodes

Post by SAKDOSS »

Perfect, thanks !
Post Reply