0

I am trying to recreate the picture attached. For some reason, I can't use the Triangle-Triangle code between two vertical bars using the draw command. I have tried different combinations, but with now luck. Here is my MWE. Thank you for your time and any help you can offer.

\documentclass[tikz]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{hobby}
\usetikzlibrary{external}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{statistics}
\usetikzlibrary{arrows.meta}
\title{Basic Tikz Graphs}
\author{nbennett }
\date{February 2022}

\begin{document}

\maketitle

\begin{tikzpicture}[important line/.style={thick}] \draw [opacity=1,important line] (-2,4) -- (2,4) -- (0,0) -- cycle;%big triangle \draw [important line,fill=white,opacity=1] (0,4) circle (2cm and 0.4cm);%top of cone \draw [fill=blue!20!white,opacity=1] (-1.49,2.98) -- (1.49,2.98) -- (0,0) -- cycle; \draw [fill=blue!10!white,opacity=1,] (0,3) circle (1.49cm and 0.3cm); \draw[dashed] (0,0) -- (0,4) --(2,4); %dashed lines \draw (1,4.18) node{\scriptsize $ 2 $}; % number \draw[dashed] (0,2.98) -- (1.49,2.98); %dashed line \draw (0.745,3.12) node{\scriptsize $ r $}; \draw[|Triangle-Triangle|] (2.4,0) -- (2.4,4); %PROBLEM IS HERE \draw[white, fill=white] (2.3,1.75) rectangle (2.5,2.25); %an empty box for the space in middle \draw (2.4,2) node{\scriptsize $ 10 $}; %a number \draw[|Triangle-Triangle|] (1.65,0) -- (1.65,2.98); %PROBLEM HERE TOO \draw[white, fill=white] (1.65,1.29) rectangle (1.65,1.69); \path(1.65,1.29)--(1.65,1.69)node[midway]{\scriptsize (h)}; \end{tikzpicture}

\end{document}

enter image description here

Nick B
  • 831

1 Answers1

2

The syntax for an arrows specification are somewhat convoluted.

The gist of it is that tip names that aren't single letter need to be ended by options, even if they're empty.

So, using

| Triangle[]-Triangle[] |

would be the correct way to specify your arrow tip.
However, since that contains ] you will need to protect this from the option parser (that looks for a ]):

\draw[{| Triangle[]-Triangle[] |}] …;
% or explicitly
\draw[arrows={| Triangle[]-Triangle[] |}] …;

The special > key can be used to maybe make this more easier:

\draw[>=Triangle, |<->|] …;

That said, you can always specify your own tip, say

TriBar/.tip = {Triangle[] Bar[]}

which you can later use as

\draw[TriBar-TriBar] …;

If you need this tip often in a picture/scope, you again use

> = TriBar

and then simply use <-> on the paths.

Code

\documentclass[tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[important line/.style={thick}]
\draw [opacity=1,important line] (-2,4) -- (2,4) -- (0,0) -- cycle;%big triangle
\draw [important line,fill=white,opacity=1] (0,4) circle (2cm and 0.4cm);%top of cone
\draw [fill=blue!20!white,opacity=1] (-1.49,2.98) -- (1.49,2.98) -- (0,0) -- cycle;
\draw [fill=blue!10!white,opacity=1,] (0,3) circle (1.49cm and 0.3cm); 
\draw[dashed] (0,0) -- (0,4) --(2,4); %dashed lines
\draw (1,4.18) node{\scriptsize $ 2 $}; % number
\draw[dashed] (0,2.98) -- (1.49,2.98); %dashed line
\draw (0.745,3.12) node{\scriptsize $ r $};
\draw[{| Triangle[]-Triangle[] |}] (2.4,0) -- (2.4,4); % ← !
\draw[white, fill=white] (2.3,1.75) rectangle (2.5,2.25); %an empty box for the space in middle
\draw (2.4,2) node{\scriptsize $ 10 $}; %a number
\draw[>=Triangle, |<->|] (1.65,0) -- (1.65,2.98); % ← !
\draw[white, fill=white] (1.65,1.29) rectangle (1.65,1.69);
\path(1.65,1.29)--(1.65,1.69)node[midway]{\scriptsize \(h\)};
\end{tikzpicture}
\end{document}

Output

enter image description here

Qrrbrbirlbel
  • 119,821