3

I am working on an agenda in knitr (using XeLaTeX). I use tikz for rounded edges around a tabular environment in the monthly overview. This is the first of several pages of the overview:

Monthly Overview

As you can see, there is a small white space at the top of the page. I believe that this white space corresponds to the location of the tikz code (As discussed here: How to avoid empty space caused by TikZ).

My question is: is there a way to remove this white space?

Here is a MWE (with a single cell and no rounded edges; highlight added manually):

\documentclass{book}
\usepackage[showframe]{geometry}
\setlength{\parindent}{0pt}        %no indenting of first line
\usepackage{tikz}                  %for rounded corners (not in mwe)
\usepackage{adjustbox}             %for scaling table to fill page

\begin{document}

\raisebox{-\height}[0pt][0pt]{% 
    \begin{adjustbox}{totalheight=\textheight, width = \linewidth}

        \begin{tikzpicture}
            \node(table){%
                \begin{tabular}{c}
                    tabular \\ 
                 \end{tabular}
            }; 
        \draw (table.north west) rectangle (table.south east);
        \end{tikzpicture}
    \end{adjustbox}
}

\end{document}

MWE

Some extra info about the MWE:

4

If I understand the requirements correctly, then I think the problem is that the TeX box that contains the tikzpicture has some non-zero depth. In the following, I use the local bounding box key to explicitly name the picture (using the current bounding box doesn't work) and then use the baseline key to set the baseline of the tikzpicture to the bottom of the picture so it the box containing the tikzpicture has no depth.

\documentclass{book}
\usepackage[showframe]{geometry}
\setlength{\parindent}{0pt}
\usepackage{tikz}   
\usepackage{adjustbox}
\begin{document}
\begin{adjustbox}{totalheight=\textheight, width=\linewidth}%
\begin{tikzpicture}[local bounding box=picture, baseline=(picture.south)]
  \node (table) {Some content}; 
  \draw (table.north west) rectangle (table.south east);
\end{tikzpicture}
\end{adjustbox}
\end{document}

enter image description here

An alternative approach is to explicitly set the bounding box of the picture to (0,0) (\textwidth, \textheight). The drawback is you have to make sure that all parts of the picture are inside the rectangle described by these points otherwise they will stick out over the sides. One way around this might be to scale the coordinate system over \textwidth and \textheight as this rather garish example shows:

\documentclass{book}
\usepackage[showframe]{geometry}
\setlength{\parindent}{0pt}
\usepackage{tikz}   
\begin{document}
\begin{tikzpicture}
\useasboundingbox (0,0) (\textwidth, \textheight);
\tikzset{x=\textwidth/10, y=\textheight/10}
\foreach \x in {0,...,9}
  \foreach \y [evaluate={\r=rnd; \g=rnd; \b=rnd;}] in {0,...,9}  
    \fill [/utils/exec=\definecolor{.}{rgb}{\r,\g,\b}, fill=.] 
      (\x, \y) rectangle ++(1, 1);
\end{tikzpicture}
\end{document} 

enter image description here

  • First method worked like a charm, thanks for the great explanation (also for the alternative solution), which helped me understand the depth component better! – Flo Aug 1 '15 at 11:09

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.