8

There is a way to write this

\begin{tikzpicture}
    \draw (0,0)--(10,0) node[midway,above] {top};
    \draw (0,0)--(10,0) node[midway,below] {bottom};
\end{tikzpicture}

drawing only one line?

enter image description here

3
  • 1
    Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Commented Dec 5, 2021 at 15:30
  • i've update it. Commented Dec 5, 2021 at 15:38
  • Welcome to TeX.SX. When you post a question, please provide a "Minimal Working Example" (MWE) that starts with \documentclass, includes all relevant \usepackage commands, ends with \end{document} and compiles without errors, even if it does not produce your desired output.
    – Sandy G
    Commented Dec 5, 2021 at 16:39

2 Answers 2

12

This may be a duplicate, but you can just write multiple nodes after the line:

MWE

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \draw (0,0) -- (10,0) node[midway,above] {top} node[midway,below] {bottom};
\end{tikzpicture}
\end{document}

Result

result

9

This is actually example from TikZ & PGF manual ... you can use quotes library

\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{quotes}

\begin{document}
\begin{tikzpicture}
  \draw[blue] (0,0) --  node[above] {top} node[below] {bottom} (10,0);
%
  \draw[red]  (0,2) to ["top", "bottom" '] (10,2);
\end{tikzpicture}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .