1

I have a plot with two horizontal lines. Both lines should have ticks, but only the lower line should have labels below the x-axis. Unfortunately, I don't know how to add ticks to the upper line, because the units are in cm and the ticks are added in pt. Do I need to convert the 1pt and -3pt to cm and put the absolute values there? I tried to mix using something like this \draw (2.5,15+1pt) -- (2.5,15-3pt) but this failed.

Here is the plot: bla

Code:

\begin{figure}
  \centering
    \begin{tikzpicture}[y=.2cm, x=.7cm]
        %axis
        \draw (1,0) -- coordinate (x axis mid) (18.9,0);
        \draw (1,15) -- coordinate (bla) (18.9,15);
        %ticks
        \draw (2.5,1pt) -- (2.5,-3pt)
            node[anchor=north] {1};
    %   \draw (2.5,1pt) -- (2.5,-3pt) <---- add here ticks on the upper horizontal line at the same x position as the lower line (1)
    \end{tikzpicture}
    \captionof{figure}{bla}
    \Description{bla}
    \label{fig:bla}
\end{figure}
John Doe
  • 29
  • 3
  • Try \draw ([yshift=1pt]2.5,15) -- ([yshift=-3pt]2.5,15) – Rmano Mar 09 '21 at 14:41
  • @Rmano Thanks. Solved it. Please add this as an answer. – John Doe Mar 09 '21 at 14:54
  • Please add a complete Minimal (non-) Working Example starting with \documentclass.... I have no problem compiling \documentclass[tikz]{standalone} \begin{document} \begin{tikzpicture}[y=.2cm, x=.7cm] \draw (2.5,15+1pt) -- (2.5,15-3pt); \end{tikzpicture} \end{document} – hpekristiansen Mar 09 '21 at 15:48
  • @hpekristiansen it does not error, but it doesn't work as expected (at least by the OP... ;-) – Rmano Mar 09 '21 at 16:44

1 Answers1

1

The coordinates without numbers are in units of the x, y arguments of the tikzpicture (default 1 cm).

In this case, one possible approach is to use shifts applied to coordinates, like:

\draw ([yshift=1pt]2.5,15) -- ([yshift=-3pt]2.5,15)

When you mix pure numbers and units, the pure number is assumed to be in pt:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[]
        %axis
        \draw [ultra thin, dotted] (0,0) grid (3,3);
        \draw (1,2) -- ++(2,0);
        \draw [red] ([yshift=5pt] 1,2) -- ++(2,0);
        \draw [blue] (1,2+5pt) -- ++(2,0);
        \node [circle, draw, green] at (1cm, 7pt){};
    \end{tikzpicture}
\end{document}

enter image description here

BTW, notice (for the next time) that this is a correct minimal working example (MWE)

Rmano
  • 40,848
  • 3
  • 64
  • 125