0

I am making a diagram of particles. Each circle at each TikZ node corresponds to a particle. For each particle, there should be the name of the particle (e.g. u) and some of its properties (e.g. charge). I would like the name of the particle to be at the center of its node and to be one font size and its characters to be below the name of the particle and to be at a smaller font size.

When I attempt to change the font size (using \scriptsize), the font size appears not to change. When I attempt to use a center environment in the text of nodes that have been set to left-aligned, there is an error.

So, what would be an appropriate way to format text for the nodes? How can multiple alignments and font sizes be used in node text?

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usepackage{siunitx}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\usetikzlibrary{fit}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{figure}[htbp]
\centering

\tikzstyle{particleblue}=[
    circle,
    thick,
    minimum size=1.5cm,
    draw=black,
    fill=blue!20
]
\tikzstyle{particlegreen}=[
    circle,
    thick,
    minimum size=1.2cm,
    draw=black,
    fill=green!20
]
\tikzstyle{particlered}=[
    circle,
    thick,
    minimum size=1.2cm,
    draw=black,
    fill=red!20
]
\tikzstyle{particleyellow}=[
    circle,
    thick,
    minimum size=1.2cm,
    draw=black,
    fill=yellow!40
]
\tikzstyle{backgroundblue}=[
    rectangle,
    fill=blue!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\tikzstyle{backgroundgreen}=[
    rectangle,
    fill=green!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\tikzstyle{backgroundred}=[
    rectangle,
    fill=red!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\tikzstyle{backgroundyellow}=[
    rectangle,
    fill=yellow!40,
    inner sep=0.2cm,
    rounded corners=5mm
]

\begin{tikzpicture}[>=latex,text depth=0.00ex]
    % elements in a matrix
    \matrix[row sep=0.5cm,column sep=0.5cm, nodes={align=left}]{
        \node (u)      [particleblue   ]{\begin{center}${\mathbf{u}}$\end{center}\scriptsize\\\\mass: ${2.3}$\,\si{MeV/c^{2}}\\charge: ${2/3}$\\spin: ${1/2}$};&
        \node (c)      [particleblue   ]{${\mathbf{c}}$};                                                                            &
        \node (t)      [particleblue   ]{${\mathbf{t}}$};                                                                            &
        \node (g)      [particlered    ]{${\mathbf{g}}$};                                                                            &
        \node (H)      [particlegreen  ]{${\mathbf{H}}$};                                                                            &
        \\
        \node (d)      [particleblue   ]{${\mathbf{d}}$};                                                                            &
        \node (s)      [particleblue   ]{${\mathbf{s}}$};                                                                            &
        \node (b)      [particleblue   ]{${\mathbf{b}}$};                                                                            &
        \node (gamma)  [particlered    ]{${\mathbf{\gamma}}$};                                                                       &
        \\
        \node (e)      [particleyellow ]{${\mathbf{e}}$};                                                                            &
        \node (mu)     [particleyellow ]{${\mathbf{\mu}}$};                                                                          &
        \node (tau)    [particleyellow ]{${\mathbf{\tau}}$};                                                                         &
        \node (Z)      [particlered    ]{${\mathbf{Z}}$};                                                                            &
        \\
        \node (nu_e)   [particleyellow ]{${\mathbf{\nu_{e}}}$};                                                                      &
        \node (nu_mu)  [particleyellow ]{${\mathbf{\nu_{\mu}}}$};                                                                    &
        \node (nu_tau) [particleyellow ]{${\mathbf{\nu_{\tau}}}$};                                                                   &
        \node (W)      [particlered    ]{${\mathbf{W}}$};                                                                            &
        \\
    };
    % background rectanges
    \begin{pgfonlayer}{background}
        \node [
            backgroundblue,
            fit=(u) (b)
        ]{};
        \node [
            backgroundyellow,
            fit=(e) (nu_tau)
        ]{};
        \node [
            backgroundred,
            fit=(g) (W)
        ]{};
        \node [
            backgroundgreen,
            fit=(H)
        ]{};
    \end{pgfonlayer}
\end{tikzpicture}

\end{figure}

\end{document}
1

I removed everything but the blue parts. By putting two nodes for each particle it is easier to set the name in the center and the rest below.

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usepackage{siunitx}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\usetikzlibrary{fit}
\usetikzlibrary{backgrounds}

\begin{document}
\tikzstyle{particleblue}=[
    circle,
    thick,
    minimum size=1.5cm,
    draw=black,
    fill=blue!20,
    minimum size=100pt
]
\tikzstyle{backgroundblue}=[
    rectangle,
    fill=blue!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\newcommand\particleblue[5]{%{label}{name}{mass}{chearge}{spin}
  \node (#1)      [particleblue   ]{\Huge$\boldsymbol{#2}$};
  \node[below=8pt] {%
    \footnotesize
    \begin{tabular}{l}
      Mass:   $#3\,\si{MeV/c^2}$\\
      Charge: $#4$ \\
      Spin:   $#5$
    \end{tabular}};
}

\begin{tikzpicture}[>=latex,text depth=0.00ex]
    % elements in a matrix
    \matrix[row sep=0.5cm,column sep=0.5cm, nodes={align=left}]{
      \particleblue{u}{u}{2.3}{2/3}{1/2} &
      \particleblue{c}{c}{78}{-2/3}{-1/2} &
      \particleblue{mu}{\mu}{4}{1/3}{1/2} &
      \\
      \particleblue{d}{d}{}{}{} &
      \particleblue{s}{s}{}{}{} &
      \particleblue{b}{b}{}{}{} &       
      \\
    };
    % background rectanges
    \begin{pgfonlayer}{background}
        \node [
            backgroundblue,
            fit=(u) (b)
        ]{};
    \end{pgfonlayer}
\end{tikzpicture}
\end{document}

enter image description here

If the node name is positioned above the center and the data below the result is, at least in my opinion, better looking. Here it is also added that if an data argument is empty it is not printed.

\renewcommand\particleblue[5]{%{label}{name}{mass}{chearge}{spin}
  \node (#1)      [particleblue   ]{};
  \node[above]{\Huge$\boldsymbol{#2}$};
  \node[below] {%
    \footnotesize
    \begin{tabular}{l}
      \ifx#3\empty \else Mass:   $#3\,\si{MeV/c^2}$\fi\\
      \ifx#4\empty \else Charge: $#4$ \fi\\
      \ifx#5\empty \else Spin:   $#5$ \fi
    \end{tabular}};
}

enter image description here

| improve this answer | |
1

enter image description here

You can only use center and related commands directly if tikz makes a "minipage" based node which it will do if you add a text width=2cm key, however here it's probably easier just to have a nested \parbox.

\documentclass[a4paper]{article}

\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\usepackage{siunitx}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}
\usetikzlibrary{fit}
\usetikzlibrary{backgrounds}

\begin{document}

\begin{figure}[htbp]
\centering

\tikzstyle{particleblue}=[
    circle,
    thick,
    minimum size=1.5cm,
    draw=black,
    fill=blue!20
]
\tikzstyle{particlegreen}=[
    circle,
    thick,
    minimum size=1.2cm,
    draw=black,
    fill=green!20
]
\tikzstyle{particlered}=[
    circle,
    thick,
    minimum size=1.2cm,
    draw=black,
    fill=red!20
]
\tikzstyle{particleyellow}=[
    circle,
    thick,
    minimum size=1.2cm,
    draw=black,
    fill=yellow!40
]
\tikzstyle{backgroundblue}=[
    rectangle,
    fill=blue!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\tikzstyle{backgroundgreen}=[
    rectangle,
    fill=green!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\tikzstyle{backgroundred}=[
    rectangle,
    fill=red!10,
    inner sep=0.2cm,
    rounded corners=5mm
]
\tikzstyle{backgroundyellow}=[
    rectangle,
    fill=yellow!40,
    inner sep=0.2cm,
    rounded corners=5mm
]

\begin{tikzpicture}[>=latex,text depth=0.00ex]
    % elements in a matrix
    \matrix[row sep=0.5cm,column sep=0.5cm, nodes={align=left}]{
        \node (u)      [particleblue   ]{\parbox{1.5cm}{%
\vspace{-12pt}%
\centering$\mathbf{u}$\par
\raggedright\scriptsize
mass: ${2.3}$\,\si{MeV/c^{2}}\\charge: ${2/3}$\\spin: ${1/2}$}};&
        \node (c)      [particleblue   ]{${\mathbf{c}}$};                                                                            &
        \node (t)      [particleblue   ]{${\mathbf{t}}$};                                                                            &
        \node (g)      [particlered    ]{${\mathbf{g}}$};                                                                            &
        \node (H)      [particlegreen  ]{${\mathbf{H}}$};                                                                            &
        \\
        \node (d)      [particleblue   ]{${\mathbf{d}}$};                                                                            &
        \node (s)      [particleblue   ]{${\mathbf{s}}$};                                                                            &
        \node (b)      [particleblue   ]{${\mathbf{b}}$};                                                                            &
        \node (gamma)  [particlered    ]{${\mathbf{\gamma}}$};                                                                       &
        \\
        \node (e)      [particleyellow ]{${\mathbf{e}}$};                                                                            &
        \node (mu)     [particleyellow ]{${\mathbf{\mu}}$};                                                                          &
        \node (tau)    [particleyellow ]{${\mathbf{\tau}}$};                                                                         &
        \node (Z)      [particlered    ]{${\mathbf{Z}}$};                                                                            &
        \\
        \node (nu_e)   [particleyellow ]{${\mathbf{\nu_{e}}}$};                                                                      &
        \node (nu_mu)  [particleyellow ]{${\mathbf{\nu_{\mu}}}$};                                                                    &
        \node (nu_tau) [particleyellow ]{${\mathbf{\nu_{\tau}}}$};                                                                   &
        \node (W)      [particlered    ]{${\mathbf{W}}$};                                                                            &
        \\
    };
    % background rectanges
    \begin{pgfonlayer}{background}
        \node [
            backgroundblue,
            fit=(u) (b)
        ]{};
        \node [
            backgroundyellow,
            fit=(e) (nu_tau)
        ]{};
        \node [
            backgroundred,
            fit=(g) (W)
        ]{};
        \node [
            backgroundgreen,
            fit=(H)
        ]{};
    \end{pgfonlayer}
\end{tikzpicture}

\end{figure}

\end{document}
| improve this answer | |

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.