26

I'm wondering how to create a node with TikZ which has different inner separations/padding on each side.

Imagine something like this:

\node [inner xsep=10pt, draw=blue, very thick, rectangle] (box) {Some Text in here};
\node [fill=blue, text=white] at (box.west) {\MySymbol}

Now, the problem is that the text is too close to my symbol -- simply increasing "inner xsep" is not a good idea, because it would look awkward on the left side of the text node.

Any hints on how to increase the padding of the right side of the box?

1
23

Using \hspace* you can manually control the padding:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node [inner xsep=10pt, draw=blue, very thick, rectangle] (a) at (0,0) {\hspace*{20pt}Some Text in here};
\node [inner xsep=30pt, draw=blue, very thick, rectangle] (d) at (0,-1) {Some Text in here\hspace*{-20pt}};
\node [inner xsep=10pt, draw=blue, very thick, rectangle] (b) at (0,-2) {Some Text in here\hspace*{20pt}};
\node [inner xsep=30pt, draw=blue, very thick, rectangle] (c) at (0,-3) {\hspace*{-20pt}Some Text in here};
\end{tikzpicture}

\end{document}

enter image description here

1
  • Thank you! This also works with \vspace for vertical padding.
    – Dylon
    Dec 3 '18 at 20:51
1

I think that a more neat approach is to use xshift key. So you use xsep to define the width of a frame and xshift to align it.

1
  • If I understand correctly, this does not shift the text inside a node, but the node position instead. A visual example would help to make this clear.
    – John
    Jul 26 at 9:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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