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 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}
share|improve this question
    
I guess it's a duplicate of this question: The tikzpicture is just too large, it doesn't fit into the text width. –  Hendrik Vogt Nov 30 '10 at 21:07
    
@Hendrik: this question is different, because here it's not just caused by the width, but also by using \centering outside of the floating figure. –  Stefan Kottwitz Nov 30 '10 at 21:10
    
@Stefan: agreed, it's a combination of 2 problems. –  Hendrik Vogt Nov 30 '10 at 21:12
    
\centering is a macro not an environment. Wrapping any environment around the figure doesn't do much. The \centering must go into it. Also a figure which should cover the whole page should use [p] not [ht] or use a non-floating environment. –  Martin Scharrer May 3 '11 at 20:33
    
I think this can be solved the same way as How to define a figure size so that is consume the rest of a page?, can't it? –  Martin Scharrer May 6 '11 at 10:17
add comment

5 Answers

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}
share|improve this answer
    
Just saw that this answer was kind of overkill as I didn't see the follow-up question ... –  Hendrik Vogt Dec 1 '10 at 10:03
add comment

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.

share|improve this answer
    
I think I'll take a look at geometry also, it sounds like a good sol'n. –  Douglass Nov 30 '10 at 21:09
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
OK, I'll give it a try. Seems to work. - thanks –  Douglass Nov 30 '10 at 21:06
add comment

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.

share|improve this answer
    
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
show 2 more comments

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.