4

Is it possible to format a single node in tikzcd? In the below MWE, I would like the \dots cell to not have an ellipse.

MWE

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{shapes}

\begin{document}

\begin{figure}
    \begin{tikzcd}[cells={nodes={draw=black, ellipse}}]
        0 \arrow[r] & 1 \arrow[r] & \dots \arrow[r] & n-1 \arrow[r] & n
    \end{tikzcd}
\end{figure}

\end{document}

1 Answers1

7

tikzcd is in fact only an improvement of matrix in TikZ.

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}
    \begin{tikzcd}[cells={nodes={draw=black, ellipse}}]
        0 \arrow[r] & 1 \arrow[r] & |[draw=none]|\dots \arrow[r] & n-1 \arrow[r] & n
    \end{tikzcd}
\end{figure}
\end{document}

enter image description here

However, to have nice arrows, I think some improvements are needed. Here are some proposals to do so:

  1. Use phantom (as suggested by marmot in the comments)

    \documentclass{article}
    \usepackage{tikz-cd}
    \usetikzlibrary{shapes}
    \begin{document}
    \begin{figure}
        \begin{tikzcd}[cells={nodes={draw=black, ellipse}}]
            0 \arrow[r] & 1 \arrow[r] & |[draw=none]|\dots\vphantom{1} \arrow[r] & n-1 \arrow[r] & n
        \end{tikzcd}
    \end{figure}
    \end{document}
    

    enter image description here

    We can even improve this approach more by using \cdots:

    \documentclass{article}
    \usepackage{tikz-cd}
    \usetikzlibrary{shapes}
    \begin{document}
    \begin{figure}
        \begin{tikzcd}[cells={nodes={draw=black, ellipse}}]
            0 \arrow[r] & 1 \arrow[r] & |[draw=none]|\cdots\vphantom{1} \arrow[r] & n-1 \arrow[r] & n
        \end{tikzcd}
    \end{figure}
    \end{document}
    

    enter image description here

  2. Use option anchor=center

    \documentclass{article}
    \usepackage{tikz-cd}
    \usetikzlibrary{shapes}
    \begin{document}
    \begin{figure}
        \begin{tikzcd}[cells={nodes={draw=black, ellipse,anchor=center}}]
            0 \arrow[r] & 1 \arrow[r] & |[draw=none]|\dots \arrow[r] & n-1 \arrow[r] & n
        \end{tikzcd}
    \end{figure}
    \end{document}
    

    enter image description here

Moreover, to make the height of the nodes consistent, you may need minimum height option (here I apply it to the anchor=center code – you can apply this to any code above):

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{shapes}
\begin{document}
\begin{figure}
    \begin{tikzcd}[cells={nodes={draw=black, ellipse,anchor=center,minimum height=2em}}]
        0 \arrow[r] & 1 \arrow[r] & |[draw=none]|\dots \arrow[r] & n-1 \arrow[r] & n
    \end{tikzcd}
\end{figure}
\end{document}

enter image description here