How can I construct a path (curve, line) but not draw it?
For example, I want to construct the following path
\draw[name path = phantom] plot coordinates {
(0, 2)
(2, 5)
(3, 7)
} ;
but do not want the actual line shown.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityThe command \draw
actually is a shortcut for \path[draw]
, if you remove the draw
option, and write only
\path
you'll have a path that is not drawn, even though TikZ will take into account its dimensions.
Possible alternatives are:
\draw[draw=none]
(which is exactly equal to a \path
command) where you say to draw a path without any color, or
\draw[opacity=0]
where you say to draw a transparent path. For a detailed explanation of the difference, see: Difference between draw=none and draw opacity=0 (also for fill=none and fill opacity=0)?
Here is an MWE with the various options, I've put a frame around the tikzpicture
s just to show that, even if the paths aren't drawn, their dimensions are taken into account.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usepackage{framed}
\begin{document}
This is your command:
\begin{framed}
\begin{tikzpicture}
\draw[name path = phantom] plot coordinates {
(0, 2)
(2, 5)
(3, 7)
};
\end{tikzpicture}
\end{framed}
This is with \texttt{\textbackslash path} only:
\begin{framed}
\begin{tikzpicture}
\path plot coordinates {
(0, 2)
(2, 5)
(3, 7)
} ;
\end{tikzpicture}
\end{framed}
\newpage
This is with \texttt{\textbackslash draw[draw=none]}:
\begin{framed}
\begin{tikzpicture}
\draw[draw=none] plot coordinates {
(0, 2)
(2, 5)
(3, 7)
} ;
\end{tikzpicture}
\end{framed}
This is with \texttt{\textbackslash draw[opacity=0]}:
\begin{framed}
\begin{tikzpicture}
\draw[opacity=0] plot coordinates {
(0, 2)
(2, 5)
(3, 7)
} ;
\end{tikzpicture}
\end{framed}
\end{document}
An extension to the list of CarLaTeX.
The source code TDS:tex/generic/pgf/basiclayer/pgfcorelayers.code.tex
reveals a special layer that is discarded (it is not documented in the TikZ manual 3.0.1a):
\def\pgfdiscardlayername{discard}
\def\pgfonlayer@assert@is@active{%
\ifx\pgfonlayer@name\pgfdiscardlayername
% this special layer name can be used as /dev/null without
% warning.
...
The next file intersects the plot of the question with a circle, adds a node in the center and draws a line from the intersection points to the left and right of the node:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\path (2, 5) node[draw] (hw) {Hello World};
\draw[name path=phantom] plot coordinates {
(0, 2)
(2, 5)
(3, 7)
};
\draw[name path=circle] (2, 5) circle[radius=2];
\draw[name intersections={of=phantom and circle}]
(intersection-1) -- (hw.south west)
-- (hw.north east) -- (intersection-2)
;
\end{tikzpicture}
\end{document}
Now, we hide the plot of the question and the node by putting them on the discarded layer:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\pgfdeclarelayer{discard}
\begin{pgfonlayer}{discard}
\path (2, 5) node (hw) {Hello World}; % or node[draw]
\path[name path=phantom] plot coordinates { % or \draw
(0, 2)
(2, 5)
(3, 7)
};
\end{pgfonlayer}
\draw[name path=circle] (2, 5) circle[radius=2];
\draw[name intersections={of=phantom and circle}]
(intersection-1) -- (hw.south west)
-- (hw.north east) -- (intersection-2)
;
\end{tikzpicture}
\end{document}
Because the discarded layer is not added to the output file, the PDF file size shrinks from 11696 to 1198 bytes (both: pdflatex
with \pagestyle{empty}
).
\path
instead of\draw
draw=none
andopacity=0
as well, if you like, and possibly refer to tex.stackexchange.com/questions/67711.