Tx · LaTeX & TikZ

How to Fit a TikZ Figure on a Landscape Page

Published By the 9to5Science editorial team

At a glance

  1. 1. Rotate the page

    Use the pdflscape package’s landscape environment to create a landscape page that PDF viewers display rotated.

  2. 2. Set a size limit

    Wrap the TikZ picture in adjustbox and cap both its width and height to leave room for the caption.

  3. 3. Place the float

    Use a page float or non-floating content, then check the compiled PDF for clipping and readability.

  4. 4. Simplify if needed

    If labels become too small, shorten them, reduce spacing, or split the figure instead of shrinking it further.

A wide TikZ diagram often needs more room than a portrait page provides. Rotating the page gives it landscape dimensions, but it does not automatically resize the drawing; a picture that is too wide or tall can still run off the page.

The example below uses pdflscape to make a landscape page and adjustbox to limit the picture’s width and height. The limits leave room for the caption as well as the page margins.

Complete example

This example uses the article class, TikZ, pdflscape, and adjustbox:

\documentclass[a4paper]{article}
\usepackage[margin=25mm]{geometry}
\usepackage{tikz}
\usepackage{pdflscape}
\usepackage{adjustbox}

\begin{document}

\begin{landscape}
\begin{figure}[p]
  \centering
  \begin{adjustbox}{max totalsize={0.95\linewidth}{0.75\textheight}}
    \begin{tikzpicture}[
      every node/.style={draw, rounded corners, inner sep=4pt},
      level 1/.style={sibling distance=55mm, level distance=18mm},
      level 2/.style={sibling distance=27mm, level distance=18mm},
      edge from parent/.style={draw}
    ]
      \node {Root}
        child { node {Branch A}
          child { node {Leaf A1} }
          child { node {Leaf A2} }
        }
        child { node {Branch B}
          child { node {Leaf B1} }
          child { node {Leaf B2} }
        };
    \end{tikzpicture}
  \end{adjustbox}
  \caption{A tree constrained to fit on a landscape page.}
  \label{fig:landscape-tree}
\end{figure}
\end{landscape}

\end{document}

Compile the document and inspect the PDF. pdflscape rotates the page for display in most PDF viewers, while adjustbox scales the picture down only as much as needed to satisfy the maximum dimensions. The 0.95\linewidth and 0.75\textheight limits are deliberately smaller than the full available area: the caption and the page layout also need space.

Why constrain both dimensions?

A width-only limit such as \resizebox{\linewidth}{!}{...} preserves the picture’s proportions, but it does not prevent a tall diagram from exceeding the page height. Conversely, a height-only limit cannot prevent an unusually wide diagram from overflowing horizontally.

The max totalsize option sets upper bounds on both dimensions while preserving the aspect ratio. In a landscape environment, \linewidth and \textheight reflect the landscape text area. Adjust the two fractions if your margins, caption, or document class need more room. Leave some spare space rather than setting the picture to the exact page boundary.

Float placement and page orientation

The [p] option asks LaTeX to place the figure on a float page. Float placement is a request, not an absolute guarantee; LaTeX may defer a figure if it cannot place it under the document’s float rules. The landscape environment applies to the material placed within it, so keep the figure inside that environment. If the figure lands on an unexpected page or orientation, check the surrounding floats and the compiled PDF rather than assuming the source-code position determines the final position.

For content that must appear exactly at that point, you can omit the figure environment and use a caption mechanism such as \captionof{figure} from the caption package. This gives up normal float placement, so use it only when fixed placement is more important than LaTeX’s float management.

If the figure is still too large

First reduce TikZ spacing, simplify the tree, or shorten long node labels. You can also split a large diagram across pages or redesign it as several smaller diagrams. Scaling the entire picture reduces its text and line widths too, which can make labels difficult to read in print.

TikZ’s scale option is another way to change a picture’s size, but it does not scale node shapes and text by default. Adding transform shape changes that behavior, but also shrinks the labels. For a whole-picture size limit, adjustbox is often more direct because it measures the finished picture.

Common mistakes

  • Rotating without resizing: Landscape orientation adds width, but a diagram may still exceed the landscape page’s width or height.
  • Constraining only the width: A tall figure can overflow vertically even if its width fits.
  • Using the full page dimensions: The figure still needs room for margins and its caption.
  • Shrinking before simplifying: Very small text is hard to read. Reduce unnecessary spacing or split the diagram first.
  • Expecting a float to stay exactly where it is written: LaTeX may move floats to satisfy its placement rules.

References

  1. The PGF/TikZ Manual
  2. The pdflscape package
  3. The adjustbox package

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.