5

I use \draw[|-|] () to (); to draw a few intervals.

I expect that each interval is rendered like |----| (see the 2nd and the 3rd intervals in the figure below).

However, the top and the bottom intervals below show only a half of their endpoint lines (i.e., |).

Why are these endpoint lines (|) not shown completely? How to show them?

tikz-interval


Editable ReadOnly Code@ShareLaTeX

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw[|-|, red] (0,0) to (1,0);
  \draw[|-|, red, dashed] (0,1) to (1,1);
  \draw[|-|, blue, dashed] (0,2) to (1,2);
  \draw[|-|, blue] (0,3) to (1,3);
\end{tikzpicture}
\end{document}
hengxin
  • 2,371
  • 3
    arrowheads don't modify the bounding box of the picture and standalone thinks that's the bounding box only with the lines – percusse Nov 07 '16 at 12:31
  • 1
    @percusse: you're right unless you load arrows.meta. See Till's comment from 01/08/2016 in https://sourceforge.net/p/pgf/feature-requests/77/#9229 – Ignasi Nov 07 '16 at 17:35
  • @Ignasi Well, well somebody is back :) – percusse Nov 07 '16 at 18:07

2 Answers2

7

The real margin to be chosen:

\documentclass[margin=3mm]{standalone} % here PS
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw[|-|, red] (0,0) to (1,0);
  \draw[|-|, red, dashed] (0,1) to (1,1);
  \draw[|-|, blue, dashed] (0,2) to (1,2);
  \draw[|-|, blue] (0,3) to (1,3);
\end{tikzpicture}
\end{document}

enter image description here

  • @Ignasi showed that Loading "arrows.meta" tikzlibrary, arrows tips are included in bounding box. I think this solution is better (because it gives the reason). Therefore, I have changed my mind and accepted it. Sorry for that. Thanks for your efforts. – hengxin Nov 08 '16 at 02:50
3

There's no need to change standalone border margins. Loading arrows.meta tikzlibrary, arrows tips are included in bounding box (see How to make a smarter cropping with standalone or preview packages?):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}
  \draw[|-|, red] (0,0) to (1,0);
  \draw[|-|, red, dashed] (0,1) to (1,1);
  \draw[|-|, blue, dashed] (0,2) to (1,2);
  \draw[|-|, blue] (0,3) to (1,3);
\end{tikzpicture}
\end{document}

enter image description here

Ignasi
  • 136,588