4

Consider the MWE using tikz and positioning:

\documentclass{minimal}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
  \begin{tikzpicture}
    \node (A) {A};
    \node (B) [right=1cm of A] {B};
    \draw [->] (A) -- (B);
  \end{tikzpicture}
\end{document}

I would like to eliminate the standalone definition of node B, while still producing the same output.

Something like this (illegal) attempt:

\node (A) {A};
\draw [->] (A) -- node [right=1cm of A] {B};

Sure, not a big deal, but I keep coming back to trying.

tucuxi
  • 185

2 Answers2

3

Here are a couple of options.

output of code

\documentclass{article} % never use minimal

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
  \begin{tikzpicture}
    \node (A) {A};
    \node (B) [right=1cm of A] {B};
    \draw [->] (A) -- (B);
  \end{tikzpicture}

  \begin{tikzpicture}
    \node (A) {A};
    \draw [->] (A.east) -- ++(1cm,0) node[right] {B};
  \end{tikzpicture}

  \begin{tikzpicture}
    \node (A) {A};
    \draw [->] node[right=1cm of A] (B) {B}
           (A) -- (B);
  \end{tikzpicture}

\end{document}
Torbjørn T.
  • 206,688
1

You could use tikz-cd, if you prefer. With [10em] you can adjust the lenght of the arrow.

enter image description here

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

\begin{document}
\begin{tikzcd}
A \arrow[r] &[10em] B
\end{tikzcd}
\end{document}
Sebastiano
  • 54,118