5

I would like to get this to center with 5pt margins on left, right, and top. So the picture will cover nearly the whole page with room at the bottom for captions.

\documentclass{article}
\usepackage{tikz}
\usepackage{caption}

\begin{document}
\begin{centering}
\begin{figure}[ht]


\begin{tikzpicture}[scale=(3/10)]

  \draw[help lines] (0,0) grid (600mm,500mm);

\end{tikzpicture}

\caption{some caption here}
\end{figure}
\clearpage
\end{centering}
\end{document}
lockstep
  • 250,273
Douglass
  • 501

5 Answers5

3

Here's a combination of Stefan's and Matthew's answer. Both of them addressed one of the points needed to solve your problem. To get 5pt margins on left, right, and top, use

\usepackage[left=5pt,top=5pt,right=5pt]{geometry}

For centering, put \centering inside the figure environment (just as Stefan wrote). A complete example:

\documentclass{article}
\usepackage[left=5pt,top=5pt,right=5pt]{geometry}
\usepackage{tikz}
\usepackage{caption}

\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[scale=(3/10)]
  \draw[help lines] (0,0) grid (600mm,500mm);
\end{tikzpicture}
\caption{some caption here}
\end{figure}
\end{document}

Now this does not cover nearly the whole page. For this you have to change the scale of your tikzpicture or increase the values 600mm and 500mm accordingly.

As Matten wrote in his answer, this is only a good idea for single pages. If you want to do something like this in a larger document, then you can use Stefan's answer to the question I linked to in a comment above:

\begin{figure}[ht]
\noindent
\makebox[\textwidth]{
  \begin{tikzpicture}[scale=(3/10)]
    \draw[help lines] (0,0) grid (600mm,500mm);
  \end{tikzpicture}
}
\caption{some caption here}
\end{figure}
Hendrik Vogt
  • 37,935
2

It's not centering because your tikzpicture is wider than than the text width, resulting in an overfull \hbox. You can use the geometry package to change the margins.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
2

A completely different solution using absolute positioning with TikZ (this needs two compilations to show up in the correct position)

\documentclass{article}
\usepackage{tikz,caption}
\usetikzlibrary{calc}

\begin{document}
\clearpage
\thispagestyle{empty}
\begin{tikzpicture}[overlay,remember picture]
    \draw ($(current page.south west)+(5pt,0.5cm)$) grid ($(current page.north east)-(5pt,5pt)$);
    \node[anchor=base,inner sep=0cm] at (current page.south) {\parbox{\textwidth}{\captionof{figure}{The Grid}}};
\end{tikzpicture}
\clearpage
\end{document}

Of course your actual picture must be drawn in reference to (current page), e.g. by transforming the canvas so that (0,0) is at (current page.center) or at the bottom left.

Caramdir
  • 89,023
  • 26
  • 255
  • 291
1

Yes, the figure is too wide.

A very simple approach is to calculate the hskip based on the scale and the width... It is not suitable for larger documents, but for a single page okay. There are ways to alter the page margins and text width...

\documentclass{article}
\usepackage{tikz}
\usepackage{caption}

\begin{document}
\begin{figure}[ht]

\vskip-30mm\hskip-29mm
\begin{tikzpicture}[scale=(3/10)]

  \draw[help lines] (0,0) grid (600mm,500mm);

\end{tikzpicture}

\caption{some caption here}
\end{figure}
\clearpage
\end{document}`

PS: centering with floating environments like figure should always take place inside the environment

Matten
  • 5,687
0

Just use \centering inside the figure environment instead of outside. Such (list) environments don't have the desired effect on floating environments.

A remark: blank lines in the source code cause paragraph breaks. Your code has a lot of them, perhaps not all are intended to break paragraphs.

Stefan Kottwitz
  • 231,401
  • I put \begin{centering} inside. Still no change. I noticed however that the grid is vertically centered, but it still has a huge left, and top margin. – Douglass Nov 30 '10 at 20:58
  • @user2198: The picture is just too big, thus it doesn't fit into the text area. Change [scale=(3/10)] for example into [scale=(1/10)] and you will see it. Fit to the text area, or is it intended to be too wide? – Stefan Kottwitz Nov 30 '10 at 21:05
  • @Stefan after control tokens blanks are being ignored until the next token appears. – Matten Nov 30 '10 at 21:05
  • @Matten: yes, I've meant it to be a general tipp after I've seen the blank lines. – Stefan Kottwitz Nov 30 '10 at 21:08
  • @Matten: Yes, but Stefan was talking about blank lines, and there are no spaces after control tokens in the code of the OP. – Hendrik Vogt Nov 30 '10 at 21:11
  • @Stephan, @Hendrik Okay, it's good to know not to insert blank lines at good will.

    Huh, now I'm not sure about blank lines. I had a discussion with Prof. Tantau last week when to use \relax. We are always escape blank lines with % but I thought TeX also consumes blank lines when they follow a control token...

    – Matten Nov 30 '10 at 21:15
  • You got the point. A blank line stops the consuming - in contrast to line breaks and blanks. Thank you, I never stop learning :) – Matten Nov 30 '10 at 21:24