Take the 2-minute tour ×
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.

Is there a simple way to reduce the amount of white space around the TikZ in the MWE pasted below (in particular in the x direction)?

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}

\begin{document}
VRCRCRCRCC \tikz[baseline] \node[fill=yellow!30, anchor=base,inner sep=0.7pt, outer xsep=-2pt] {ABCDE}; VBZBZBBBBG
\end{document}

enter image description here

PS: This question may be a duplicate of Is there a way to control whitespace around a TikZ picture?. I posted it nevertheless since 1) my example is much simpler (and hence may have a much simpler solution) and 2) I don't see how the answers given there could help in my case. If you disagree feel free to mark my question as "exact (!) duplicate of ...".

share|improve this question

2 Answers 2

up vote 8 down vote accepted

Simply remove the white space in the source around the inline TikZ image - either remove spaces or use a percent sign at the end of the line:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\begin{document}
VRCRCRCRCC%
\tikz[baseline]
  \node[fill=yellow!30, anchor=base, inner sep=0.7pt,
     outer xsep=-2pt] {ABCDE};%
VBZBZBBBBG
\end{document}

spacing around TikZ image

share|improve this answer
    
Hhmm, OK, now I see that my question was rather stupid. In the MWE your solution of course works perfectly. The point is that in my actual document (not the MWE) the white space between a normal word and one placed in a TikZ node is somewhat larger than the white space between two normal words. In that case, your solution doesn't work because I do want words to be separated between each other bot not as much as they are when one of them is placed in a TikZ node. Unfortunately, I cannot reproduce this phenomenon in my MWE yet ... –  lpdbw Jan 28 '13 at 8:23
1  
@lpdbw Well, check the node styles, sep values, reduce a copy of your code to get the real MWE which still shows the problem. –  Stefan Kottwitz Jan 28 '13 at 8:28

I think the problem comes with the inner sep setting. Its definition in the pgfmanual is:

An additional (invisible) separation space of dimension will be added inside the shape, between the text and the shape’s background path. The effect is as if you had added appropriate horizontal and vertical skips at the beginning and end of the text to make it a bit “larger.”

For those familiar with css, this is the same as padding.

Some test code (commented): it contains some examples showing different values for some option you used.

\documentclass{article}
%\usepackage{xcolor} % no need: tikz loads xcolor
\usepackage{tikz}

\begin{document}

\begin{minipage}{0.45\textwidth}
\texttt{initial code}\\[1ex]
\texttt{no outer xsep}\\[1ex]
\texttt{no inner sep}\\[1ex]
\texttt{set 0pt to inner sep}\\[1ex]
\texttt{set 0pt only to inner xsep}\\[1ex]
\texttt{removing all spaces (sep)}\\[1ex]
\texttt{removing all spaces (xsep)}
\end{minipage}%
\begin{minipage}{0.55\textwidth}
VRCRCRCRCC \tikz[baseline] \node[fill=yellow!30, anchor=base,inner sep=0.7pt, outer xsep=-2pt] {ABCDE}; VBZBZBBBBG\\[1ex] %original code
VRCRCRCRCC \tikz[baseline] \node[fill=yellow!30, anchor=base,inner sep=0.7pt] {ABCDE}; VBZBZBBBBG\\[1ex] % without outer xsep
VRCRCRCRCC \tikz[baseline] \node[fill=yellow!30, anchor=base,outer xsep=-2pt] {ABCDE}; VBZBZBBBBG\\[1ex] % completely different: initially it's .333em much larger than your 0.7pt
VRCRCRCRCC \tikz[baseline] \node[fill=yellow!30, anchor=base,inner sep=0pt] {ABCDE}; VBZBZBBBBG\\[1ex] % so setting inner sep to 0pt removes completely the white space in both x,y directions
VRCRCRCRCC \tikz[baseline] \node[fill=yellow!30, anchor=base,inner xsep=0pt] {ABCDE}; VBZBZBBBBG\\[1ex] % removed just in x direction
VRCRCRCRCC\tikz[baseline] \node[fill=yellow!30, anchor=base,inner sep=0pt] {ABCDE};VBZBZBBBBG\\[1ex]
VRCRCRCRCC\tikz[baseline] \node[fill=yellow!30, anchor=base,inner xsep=0pt] {ABCDE};VBZBZBBBBG
\end{minipage}

\end{document}

The result:

enter image description here

share|improve this answer

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.