5

I have a document which looks like this:

enter image description here

Code is like this:

\documentclass[10pt]{memoir}
\usepackage{lipsum}
\usepackage{tikz}

\usetikzlibrary{shapes,backgrounds,patterns}
\tikzstyle{box} = [align=center, text width=12.4cm, draw=blue, fill=blue, rectangle, rounded corners, 
                   inner sep=5pt, inner ysep=5pt]

\begin{document}
  \lipsum 
  ~\\
  \begin{tikzpicture}
  \node[box](box){\color{white}\textbf{white text on blue background}};
  \node[shape=circle,fill=white,inner sep=2mm] at (box.west) {};
  \node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
  \end{tikzpicture}
  ~\\
  \lipsum 
\end{document}

I'd like the tikzpicture not to be indented and to be vertically aligned with the text. I tried with \noindent before \begin{tikzpicture} but it doesn't seem to work ...

Any suggestion?

3 Answers 3

5

If you add draw to your circle node, you will see that your box IS aligned with the text. If you do not want the left of the circle to be counted against the bounding box, use overlay:

\node[shape=circle,fill=white,inner sep=2mm, overlay] at (box.west) {};

Even better solution is to join the two last nodes:

  \lipsum 
  ~\\
  \begin{tikzpicture}
  \node[box](box){\color{white}\textbf{white text on blue background}};
  \node[shape=circle,fill=white,
     text=blue,right=-3pt] at (box.west) {\textbf{1}};
  \end{tikzpicture}
  ~\\
  \lipsum 
1
  • wow, I completely forgot the circle! Thank you very much! :)
    – d-cmst
    Commented Jan 16, 2013 at 20:09
6

The white circle contributes to the bounding box of the tikzpicture. That can be turned off by optionoverlay. Then it remains theinner sepof the text inside the circle. The example below compensates by using\hspace*` (star form at the beginning of a line). Also it reduces the width of the box for better fitting into the line width.

\documentclass[10pt]{memoir}
\usepackage{lipsum}
\usepackage{tikz}

\usetikzlibrary{shapes,backgrounds,patterns}
\tikzstyle{box} = [align=center, text width=\the\dimexpr\linewidth-10pt\relax,
  draw=blue, fill=blue,
  rectangle, rounded corners,
  inner sep=5pt, inner ysep=5pt]

\begin{document}
  \lipsum
  ~\\
  \hspace*{-.3333em}%
  \begin{tikzpicture}
  \node[box](box){\color{white}\textbf{white text on blue background}};
  \node[overlay,shape=circle,fill=white,inner sep=2mm] at (box.west) {};
  \node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
  \end{tikzpicture}
  ~\\
  \lipsum
\end{document}

Result

0
3

Well, it is actually vertically aligned. For example, if we color the circle green, like this:

\begin{tikzpicture}
\node[box] (box){\color{white}\textbf{white text on blue background}};
\node[shape=circle,fill=green,inner sep=2mm] at (box.west) {};
\node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
\draw [brown] (current bounding box.south west) rectangle 
              (current bounding box.north east);
\end{tikzpicture}

We get

With green circle

So I guess what you want is to place some of the circle outside of the bounding box, like this:

  \begin{tikzpicture}
  \node[box] (box){\color{white}\textbf{white text on blue background}};
  \node[shape=circle,fill=white,inner sep=2mm] at (box.west) (circle) {};
  \node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
  \pgfresetboundingbox
  \useasboundingbox (circle.north) rectangle (box.south east);
  \end{tikzpicture}

From which you get

Correct

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .