13

I am not sure whether this is possible or not.
I would like to have some control on the horizontal alignment of columns in tikzcd.

In particular I would like to be able to mimic (on some of my diagrams) the right alignment - left alignment alternation.

So, I would like that the first diagram in the following MWE aligns like the second one

\documentclass[a4paper,11pt,fleqn,oneside]{book}%
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{matrix, arrows, cd, patterns}

\begin{document}

\begin{tikzcd}[baseline=(current  bounding  box.center), row sep = 0ex]
    \text{something long} \arrow[r] & \text{something else long}\\
    a         \arrow[r, mapsto] &  b
\end{tikzcd}

\begin{align*}
    \text{something long} & \longrightarrow \text{something else long}\\
    a         &\longmapsto   b
\end{align*}

\end{document}

image of the two diagrams

Is it possible to do it? How?
I already tried with the column 1./style={anchor=base east} (and base west) but with no success.

dadexix86
  • 651

1 Answers1

14

In the meantime of me thinking about something more clever, you can go with

% arara: pdflatex

\documentclass[a4paper,11pt,fleqn,oneside]{book}
\usepackage{mathtools}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[row sep = 0ex, column sep=1.9em]
    \text{something long} \arrow{r} & \text{something else long}\\
    \makebox[\widthof{something long}][r]{$a$} \arrow[mapsto]{r} &  \makebox[\widthof{something else long}][l]{$b$}
\end{tikzcd}
\begin{align*}
    \text{something long} & \longrightarrow \text{something else long}\\
    a         &\longmapsto   b
\end{align*}    
\end{document}

if you do not need that too often.


And here comes something more clever:

% arara: pdflatex

\documentclass[a4paper,11pt,fleqn,oneside]{book}
\usepackage{mathtools}
\usepackage{tikz-cd}

\begin{document}
\begin{tikzcd}[%
    ,row sep = 0ex
    ,/tikz/column 1/.append style={anchor=base east}
    ,/tikz/column 2/.append style={anchor=base west}
    ]
    \text{something long} \arrow{r} & \text{something else long} \\
    a \arrow[mapsto]{r} & b
\end{tikzcd}
\end{document}

Hope, this is what you need.

enter image description here

LaRiFaRi
  • 43,807
  • similar syntax can be found in the first two examples on http://tex.stackexchange.com/a/142718 – LaRiFaRi Jan 25 '16 at 12:33
  • This solution works, but it is "per cell", while i would like to have a "per column" solution, and more automatic if it's possible. The first one in the linked discussion looks promising, but one has to manually select what is the longest cell in every column. It would be perfect if that can be made automatic :) – dadexix86 Jan 25 '16 at 12:51
  • @dadexix86 Please see my update. This should be enough automation, I guess. – LaRiFaRi Jan 25 '16 at 12:58
  • Yes! :D This is exactly what I was looking for! I did not know about this syntax "/tikz/..." Thank you very much! – dadexix86 Jan 25 '16 at 13:01
  • @dadexix86 Me neither :-). You are very welcome. – LaRiFaRi Jan 25 '16 at 13:03