7

I'm trying to design a seating chart for my classroom. I've done this using pstricks. I wanted to try it in tikz.

What I'm doing is drawing a rectangle to represent each desk. Since the desks are arranged into groups of four, I then group these four rectangles together. The problem I'm having is when I try to group them together, I'm getting unexpected whitespace.

Here's a MWE:

\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\setlength{\parindent}{0pt}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand{\mysmallbox}{%%"
  \begin{tikzpicture}
    \node (A) at (0,0) {};
    \node (B) at (6,4) {};
    \draw (A) rectangle (B);
    \draw (A.center|-B.center) -- (A.center-|B.center);
  \end{tikzpicture}}

\newcommand{\boxesInboxes}{%%'
  \begin{tikzpicture}
    \node (A) at (3,2) {\mysmallbox};
    \node (B) at (9,6) {\mysmallbox};
    \draw[color=red,line width=0.1pt] (0,0) rectangle (12,8);
  \end{tikzpicture}}

\pagestyle{empty}
\begin{document}

\mysmallbox

\boxesInboxes

\end{document}

enter image description here

Where is the whitespace coming from?

UPDATE

I found this solution about bounding boxes. That seems far more complicated than I want. Is there a simpler way of pruning the extra white space?

I also found this solution about setting the bounding box, but I still get a little bit of white space in front of the picture.

6

A node will have inner separation. Make it zero. Further, it is advisable to use coordinates here.

\documentclass{article}
\usepackage[margin=1in,showframe]{geometry}
\setlength{\parindent}{0pt}
\usepackage{tikz}
\usetikzlibrary{calc}

%\newcommand{\mysmallbox}{%%"
%  \begin{tikzpicture}
%    \node (A) at (0,0) {};
%    \node (B) at (6,4) {};
%    \draw (A) rectangle (B);
%    \draw (A.center|-B.center) -- (A.center-|B.center);
%  \end{tikzpicture}}


%% Use coordinate to see the difference
\newcommand{\mysmallbox}{%%
  \begin{tikzpicture}
    \coordinate (A) at (0,0) {};
    \coordinate (B) at (6,4) {};
    \draw (A) rectangle (B);
    \draw (A|-B) -- (A-|B);
  \end{tikzpicture}}

\newcommand{\boxesInboxes}{%%
  \begin{tikzpicture}
    \node[inner sep=0pt] (A) at (3,2) {\mysmallbox};
    \node[inner sep=0pt] (B) at (9,6) {\mysmallbox};
    \draw[color=red,line width=0.1pt] (0,0) rectangle (12,8);
  \end{tikzpicture}}

\pagestyle{empty}
\begin{document}

\mysmallbox

\boxesInboxes

\end{document}

enter image description here

  • That fixes things for my MWE. But, I've still got a tiny bit of whitespace creeping in to my real document. :*( I'll see whether I can narrow it down some more and post an update in case I can't get rid of the space. – A.Ellett Aug 13 '13 at 1:50
  • @A.Ellett Sure. – user11232 Aug 13 '13 at 1:56
  • You could also kill the outer separation: outer sep=0pt. – Gonzalo Medina Aug 13 '13 at 2:25
  • This works perfectly. I found where how my other white space was creeping in. inner sep=0pt did the trick. – A.Ellett Aug 13 '13 at 3:04

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.