Page LayoutTikz graybox \textwidth problem?

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
csmgroup
Posts: 25
Joined: Sat Jul 17, 2010 6:58 pm

Tikz graybox \textwidth problem?

Post by csmgroup »

I need to draw round grayed box using tikz. The problem is that I need to reduce -5ex to fit into the box in a graybox. Why is this? Why \textwidth is not the width of the gray box?

Code: Select all

\documentclass{article}
\usepackage{layouts}

\usepackage{tikz}

\newlength{\mytikzwidth}
\setlength{\mytikzwidth}{\textwidth}
\addtolength{\mytikzwidth}{-5ex} % this 5ex is just rule of thumb.
\verb|capital| is a Map\footnote{The example uses country and capital,
  and it can be described as a map. Isn't it intentioanl?}, so it
understands the meaning of `+=' if the input is \verb|( -> )|.

\begin{document}

\noindent\begin{tikzpicture}
  \draw node[draw=black,fill=black!20,rounded corners,inner sep=2ex,text width=\mytikzwidth] {
    Lorem ipsum dolor sit amet \dots
    };
\end{tikzpicture}

\end{document}
Attachments
Screen shot 2010-07-30 at 6.54.37 PM.png
Screen shot 2010-07-30 at 6.54.37 PM.png (11.6 KiB) Viewed 2976 times
Last edited by csmgroup on Sun Aug 01, 2010 1:30 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

torbjorn t.
Posts: 162
Joined: Wed Jun 17, 2009 10:18 pm

Tikz graybox \textwidth problem?

Post by torbjorn t. »

The option text width given to the node makes the text in the node that width. However, the node is wider than the text, as the inner separation (the distance from the text to the edge of the node) of the node is set to 2ex. As you have 2ex of space on both sides of the text, the width of the box will be 4ex wider than \mytikzwidth.

I don't know if there are any better solutions to the problem, than the one you have already found.
csmgroup
Posts: 25
Joined: Sat Jul 17, 2010 6:58 pm

Re: Tikz graybox \textwidth problem?

Post by csmgroup »

That makes sense, and I experimented to check subtracting 2*sep from the textwidth gives me well aligned gray box.

Thanks a lot for the help.
Post Reply