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.

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?

share|improve this question
add comment

3 Answers

up vote 5 down vote accepted

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 
share|improve this answer
    
wow, I completely forgot the circle! Thank you very much! :) –  dcmst Jan 16 '13 at 20:09
add comment

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

share|improve this answer
    
thank you for all the suggestions! –  dcmst Jan 16 '13 at 20:42
add comment

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

share|improve this answer
add comment

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.