2

I'm writing examples how to calculate a concentration for my students, but I stuck at mixing rule. I thought to draw this by tikz, but I don't have an idea how to do this. It should looks like on this photo.

enter image description here

Can someone help me, please?

2

1 Answer 1

2

Here's a suggestion using the tikz-cd package/library.

The generic anchor text right allows us to add a label to the right of the last column without it messing up the placement of the lines between the cells (which always point to the center of a node).

I'm not defining \C globally but only with install C shortcut inside the picture as to not overwrite any other \C macros.

The commands \drar, \urar etc. are shortucuts to \ar[dr] or \arrow[dr] where d stands for down and r stands for right. Meaning, \drar draws an arrow to the cell down and right of it.

If the lines actually need to land on the most nothern and southern tip of C and m a little bit more work is necessary.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{cd}
\makeatletter
\pgfdeclaregenericanchor{text right}{%
  \pgf@sh@reanchor{#1}{base}%
  \multiply\pgf@x by 2
}
\makeatother
\tikzcdset{install C shortcut/.code=\newcommand*\C[1]{C_{\%_{##1}}}}
\begin{document}
\begin{tikzcd}[
  install C shortcut, sep=tiny, arrows={-, gray},
  cells={font=\strut, inner xsep=.2ex, inner ysep=.1ex},
  /tikz/mlabel/.style={label={[anchor=text]text right:{}=|\C{#1}-C_\%|}}
]
\C{1} \drar &        & |[ mlabel = 2 ]| m_{r_1} \dlar \\
               & C_{\%} \\
\C{2} \urar &        & |[ mlabel = 1 ]| m_{r_2} \ular
\end{tikzcd}
\end{document}

Output

enter image description here

3
  • Thank you very much. But what should I do if I want to put this into article or beamer? because when I did this, its didn't work. Commented Sep 16, 2022 at 17:50
  • @MichałSzymankiewicz You need \usepackage{tikz}\usetikzlibrary{cd} or \usepackage{tikzcd}. tikzcd loads tikz and its own cd library. Commented Sep 16, 2022 at 17:56
  • Ok, now it work properly. Thank you again :) . Commented Sep 16, 2022 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .