I'm not quite sure what you mean by
Note: I deliberately write "at a specific place", and not just the special cases of left and right alignments.
What other kind of alignments are there?
Case 1
Case 1 is actually the easiest.
- I know that Case 1 is not possible since the columns (and rows) are formed by centering the cells.
No, they aren't. They are aligned by their coordinate systems.
The rows align by y = 0 and the columns align by x = 0.
(Though, they are some pitfalls.)
Since every node is placed by default at (0, 0) you can just change its anchor.
By default, all nodes in a matrix of math nodes
are placed at their base
anchor.
This means the columns are horizontally centered and the rows are aligned by their baseline. By changing this to base west
or base east
we can enforce left or right alignment.
In the second diagram I've added some xshift
ing that changes the position “at a specifical place”.
I'm using my ext.paths.ortho
library which provides handy styles following question and answer to “Tikz: purely vertical arrow from nodeA.south to nodeB.north”.
The shortcut *|
stands for only vertical second
and |*
stands for only vertical first
.
Code
\documentclass[varwidth]{standalone}
\usepackage{tikz-cd}
\tikzset{strut without depth/.style={text depth=+0pt, text height=+\ht\strutbox}}
\tikzcdset{
column align/.is choice,
@column align/.style n args={2}{column align/#1/.style={anchor={#2}}},
@column align/.list={{left}{base west},{right}{base east},{center}{base}},
colspec/.style={
/utils/exec=\def\pgfmathresult{0},
/utils/temp/.code={%
\edef\pgfmathresult{\pgfinteval{\pgfmathresult+1}}%
\pgfkeysalso{/tikz/column \pgfmathresult/.append style={
/tikz/commutative diagrams/column align/##1}}},
/utils/temp/.list={#1}}}
\usetikzlibrary{ext.paths.ortho}
\begin{document}
\[
\begin{tikzcd}[
cells={strut without depth, nodes={draw=gray}},
math mode=false,
/tikz/ortho/install shortcuts,
colspec={right, left},
]
Math is excellent! \ar[r, rightarrow]
\ar[d, *|, leftarrow]
& w \ar[d, |*, rightarrow] \\
w \ar[r, leftarrow]
& Pythagoreans killed someone!
\end{tikzcd}
\]
\[
\begin{tikzcd}[
cells={strut without depth, nodes={draw=gray}},
math mode=false,
/tikz/ortho/install shortcuts,
colspec={right, left},
]
Math is excellent! \ar[r, rightarrow]
\ar[d, *|, leftarrow]
& |[xshift=1cm]| w \ar[d, |*, rightarrow] \\
|[xshift=-.5cm]| w \ar[r, leftarrow]
& Pythagoreans killed someone!
\end{tikzcd}
\]
\end{document}
Output

Case 2
Again, with purely left, right and center alignment, this is possible.
This is basically the same as case 1 just with a fitted node around the actual contant which uses my ext.node-families
library.
I've added a third and centered column to highlight why from'
and/or to'
is necessary to switch between the smaller nodes and the bigger drawn ones.
We could even invert that toggle (by naming the inner nodes with a '
and the drawn nodes without one).
This uses a custom fit
key (that also only scans one node) because TikZ-CD uses a special asymmetrical rectangle
shape.
For other alignments than left/right/center, i.e. as above with xshift
, an adjustment to the fit
key is necessary.
We could also do something like I did in my answer for “Make two nodes occupy the space of one node” where you can just go haywire with your placement and place a subnode inside it and have it act almost like a proper node.
Code
\documentclass[varwidth]{standalone}
\usepackage{tikz-cd}
\tikzcdset{
@column align/.style n args={4}{
column align/#1/.style={
anchor={#2}, /tikz/commutative diagrams/@make box of column/.style={
anchor={#3}, at={(\tikzlastnode.#4)}}}},
column align/.is choice,
@column align/.list={
{left} {base west}{real west} {real west},
{right} {base east}{real east} {real east},
{center}{base} {real center}{real center}},
colspec/.style={
/utils/exec=\def\pgfmathresult{0},
/utils/temp/.code={%
\edef\pgfmathresult{\pgfinteval{\pgfmathresult+1}}%
\pgfkeysalso{/tikz/column \pgfmathresult/.append style={
/tikz/commutative diagrams/column align/##1}}},
/utils/temp/.list={#1}},
make box of column/.style={
inner sep=+0pt, outer sep=+0pt, minimum size=+0pt,
commutative diagrams/fit=\tikzlastnode,name=\tikzlastnode',
node family/width=\tikzmatrixname-\the\pgfmatrixcurrentcolumn,
commutative diagrams/@make box of column,
append after command={(\tikzlastnode.south west) edge[
commutative diagrams/column box/.try,to path={
([xshift=+.5\pgflinewidth,yshift=+.5\pgflinewidth]\tikztostart)
rectangle([xshift=+-.5\pgflinewidth,yshift=+-.5\pgflinewidth]%
\tikztotarget)}](\tikzlastnode.north east)}},
make column box/.style={
append after command={
[every node/.code=]node[commutative diagrams/make box of column]{}}}}
\makeatletter
\tikzcdset{
fit/.code={% tikz-cd uses an asymmetrical rectangle …
\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@pp@name{#1}}{west}}
{\pgfpointanchor{\tikz@pp@name{#1}}{east}}}%
\pgfkeysalso{/tikz/text width/.expanded=+\the\pgf@x}%
\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@pp@name{#1}}{base}}
{\pgfpointanchor{\tikz@pp@name{#1}}{north}}}%
\pgfkeysalso{/tikz/text height/.expanded=+\the\pgf@y}%
\pgf@process{\pgfpointdiff{\pgfpointanchor{\tikz@pp@name{#1}}{south}}
{\pgfpointanchor{\tikz@pp@name{#1}}{base}}}%
\pgfkeysalso{/tikz/text depth/.expanded=+\the\pgf@y}},
from'/.code=\edef\tikzcd@ar@start{\tikzcd@ar@start'},
to'/.code=\edef\tikzcd@ar@target{\tikzcd@ar@target'}}
\makeatother
\usetikzlibrary{ext.paths.ortho,ext.node-families,fit}
\begin{document}
\[
\begin{tikzcd}[
cells={
text depth=+0pt, text height=+.7em,% \strut without depth
nodes={commutative diagrams/make column box}},
math mode=false,
/tikz/ortho/install shortcuts,
colspec={right, left, center}
]
Math is excellent!
\ar[r, rightarrow]
\ar[d, *|, leftarrow]
& w \ar[d, |*, rightarrow] \rar[from', to']
& Foo \\
w \ar[r, leftarrow]
& Pythagoreans killed someone!
& Baaaaaaaaaar
\end{tikzcd}
\]
\end{document}
Output

tikz-cd
mandatory for your future use? If not, I think that a simple TikZ graph would be a better solution.tikz-cd
.tikz-cd
. Hope someone will find a solution for you.