Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In TikZ, there are draw=none and fill=none options to turn off stroking and filling operations. However, there doesn't appear to be a corresponding text=none option. If I try \tikz \node[text=none] {X};, I get the error message "Package xcolor Error: Undefined color `none'." (The text=red option does work as expected.)

  • Is there indeed no text=none option?
  • What are alternatives? Is it reasonable to use text opacity=0, or is there something better?

I'm asking because I would like to create an "empty" node of the same size as a given image or text. By referencing the anchors of this "empty" node, I can then animate the image or text moving in to occupy the same space. The following is an example of what I'm trying to accomplish. It uses text opacity=0 based on @percusse's suggestion.

\documentclass{minimal}
\usepackage{animate}
\usepackage{tikz}

\usetikzlibrary{calc}

\begin{document}

\begin{animateinline}[autoplay,loop]{10}
  \multiframe{11}{iframe=0+1}{
    \begin{tikzpicture}[every node/.style={draw}]
      \node[text opacity=0] (source) {Text};
      \node[text opacity=0] (target) at (2,2) {Text};

      \node at ($(source)!\iframe/10!(target)$) {Text};
    \end{tikzpicture}
  }
\end{animateinline}

\end{document}
  • Given this ultimate goal, is it preferable to use something like \node {\phantom{Text}};?
share|improve this question
Are you basically just trying to set the size of the node, and you're using some text string to achieve this? In that case it's best to just use options like minimum width, and inner sep, as percusse said, instead of fiddling around with strings of text that have the right size. – Jake Jun 10 '12 at 21:40
@Jake I've edited my post with an example. – Henry DeYoung Jun 10 '12 at 21:57
Ah yes, thanks! In that case, I think the text opacity key is the most practical. – Jake Jun 10 '12 at 21:59
The only difference I can see is the text selection in the resulting .pdf. Opacity leaves the text selectable but \phantom doesn't. – percusse Jun 10 '12 at 22:07

3 Answers

up vote 7 down vote accepted

If you don't need the text then it shouldn't be there anyway. Either you enlarge the node with minimum width,height,inner sep etc. or you can use the text opacity key comfortably.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[text opacity=0,draw=red,fill=yellow!25] (a) {Text};
\end{tikzpicture}
\end{document}

enter image description here

If you also need some placeholder for a text, you can go slightly esoteric and get the width depth height info beforehand e.g. just for the width;

\begin{tikzpicture}
\pgfmathparse{width{"Text"}}
\edef\mywidth{\pgfmathresult}
\node[minimum width=\mywidth pt,draw=red,fill=yellow!25] (a) {};
\end{tikzpicture}
share|improve this answer
@percusse Should text opacity=0 be preferred over using \phantom? – Henry DeYoung Jun 10 '12 at 21:39
@HenryDeYoung Opacity solution does not get complicated if you make the node text \large etc. but you have to somehow send those font adjustments into the \phantom command say when the node is scaled etc. it may be a little more tedious in terms of code flexibility but I can't think of any obvious big reason for preference. – percusse Jun 10 '12 at 21:53
@Jake I was wondering about the image inclusion detail but indeed I don't see any reason why not to use. – percusse Jun 10 '12 at 21:54
text opacity=0 might not be the best option when you want to print it. I once had the following issue: the text of my nodes was not visible in the pdf, but small parts of them appeared in the printed version. I "solved" the issue by setting the text color to the background color. – Tom Bombadil Jun 11 '12 at 0:00
1  
With text opacity=0, the text is always included in PDF: you can copy it. So, \phantom seems best in terms of confidentiality. – Paul Gaborit Jun 11 '12 at 0:40
show 4 more comments

you can use \phantom{Text}

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\node[draw=red,fill=yellow!25] (a) {\phantom{Text}};
\end{tikzpicture}
\begin{tikzpicture}
\node[draw=red,fill=yellow!25] (a) {{Text}};
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

And why not : text = yellow!25 ?

and like Andrew wrote in his comment : \node[yellow!25,fill,draw=red] (a) {Text}; in this case, you set the colors for text, draw and fill.

draw and fill are different options. If you don't use these options, by default the shape is not draw and not filled but with text (it's equivalent to draw=false), the text is always displayed and by default the color used is black.

If you write \node[name=s] (a) {Text}; the name of the node is a, if it was possible to write \node[text=none] (a) {Text}; the text will be Text. text is a color; if you want you can define : \definecolor{none}{rgb}{1,1,1} and it's possible to define none to be the fill color.

\documentclass{scrartcl}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[text=yellow!25,draw=red,fill=yellow!25] (a) {Text};
\end{tikzpicture}
\end{document}
share|improve this answer
2  
Or \node[yellow!25,fill,draw=red] (a) {Text}; as a colour by itself sets all three colours to it (text,fill, and draw). This makes it easier to modify later as there's only one colour to change. – Andrew Stacey Jun 11 '12 at 7:21
yes Andrew you are right. I updated my answer. – Alain Matthes Jun 11 '12 at 7:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.