3

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}
6

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

| improve this answer | |
  • Sorry, I thought I had. – David Poxon Apr 14 '19 at 4:09
  • @DavidPoxon No problems :) You're welcome. – user156344 Apr 14 '19 at 4:10
  • 1
    @marmot Thanks for pointing that out :) I added your proposal and two more to my answer. – user156344 Apr 14 '19 at 4:44
  • Out of curiosity, what does \vphantom{1} do here? – David Poxon Apr 14 '19 at 5:19
  • @DavidPoxon \phantom{1} gives an invisible 1; \hphantom{1} gives a space which is as wide as a 1, and \vphantom{1} gives a vertical space which is as high as a 1. Read more: tex.stackexchange.com/a/4523/156344 – user156344 Apr 14 '19 at 5:28

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.