3

What is the best way to create one TikZ-node like this?

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\pgfmathsetlengthmacro\cellwidth{12mm}

\begin{document}
\begin{tikzpicture}[
Cell/.style={align=center, inner sep=0pt, 
text width=\cellwidth,
minimum height=\cellwidth,
draw=black, fill=purple, 
font=\sffamily
},
]

\node[Cell]{Ba};
\end{tikzpicture}
\end{document}

enter image description here

5
  • Call it (Ba), then add \node[anchor=north west, inner sep=1pt, font=\small] at (Ba.north west){56}; and so on... ? – Rmano May 12 at 10:01
  • Just for interests: Is there a way to put all the annotations into one node? – cis May 12 at 11:45
  • maybe you can put a tabular into the node, or a minipage. But you will lose flexibility – Rmano May 12 at 12:01
  • Yes, I know this; but I will make this atomatically with a raw-data-table and a TikZ-matrix. – cis May 12 at 15:04
6

labels can also be written inside nodes

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\newcommand{\cell}[7][]{
    \node[minimum size=7em, draw, font=\huge, 
        label={[anchor=north west]north west:#4},
        label={[anchor=north east]north east:#5},
        label={[anchor=south west]south west:#6},
        label={[anchor=south east]south east:#7},
        label={[anchor=south,yshift=3.5ex, font=\small]south:#3},
    #1] (#2) {#2};
}

\begin{tikzpicture}
\cell[fill=purple]{Ba}{Barium}{137.328}{56}{3.59}{0.89}
\cell[fill=red!30, below=0pt of Ba]{Li}{Litium}{137.328}{56}{3.59}{0.89}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Ah, with several labels, I understand. – cis May 12 at 15:24
6

like this

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\pgfmathsetlengthmacro\cellwidth{12mm}

\begin{document}

\newcommand{\cell}[6]{
\node[minimum size=7em,draw,fill=purple] (symb) {\huge #1};
\node[below =0.5em of symb.center]{\small #2};
\node[below left=0em of symb.north east](mass){#3};
\node[below right=0em of symb.north west](nb){#4};
\node[above left=0em of symb.south east](n5){#5};
\node[above right=0em of symb.south west](n6){#6};
}

\begin{tikzpicture}
\cell{Ba}{Barium}{137,328}{56}{3,59}{0,89}


\end{tikzpicture}
\end{document}

enter image description here

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.