80

I'd like to place a table on a new page with landscape orientation. To do so, I use

\usepackage{pdflscape}
...
\pagestyle{empty}
\begin{landscape}
\begin{table}[htbp]
\begin{center}
\begin{tabular}{llll}
...
\end{tabular}
\end{center}
\end{table} 
\end{landscape}
\pagestyle{plain}

However, this clears the current page, places the table on the next page with landscape orientation, and restarts typesetting in a new page with portrait orientation.

Question I'd like to place the table on a new page (as it is currently done) but to avoid to clear the current page. Is that possible?

Thanks!

lockstep
  • 250,273
Marco
  • 4,435

3 Answers3

82

Similar like my answer to How to wrap text around landscape page I would use \afterpage from the afterpage package to place the table at the next page of where it was declared. Here a non-floating replacement of table is used instead, e.g. the \captionof{table}{...} is used (capt-of or caption) package.

One issue are potential other tables which should be flushed beforehand. Otherwise the non-floating table replacement might appear earlier.

\documentclass{article}

\usepackage{pdflscape}
\usepackage{afterpage}
\usepackage{capt-of}% or use the larger `caption` package

\usepackage{lipsum}% dummy text
\begin{document}
\lipsum % Text before
\afterpage{%
    \clearpage% Flush earlier floats (otherwise order might not be correct)
    \thispagestyle{empty}% empty page style (?)
    \begin{landscape}% Landscape page
        \centering % Center table
        \begin{tabular}{llll}
            A & B & C & D \\
        \end{tabular}
        \captionof{table}{Table caption}% Add 'table' caption
    \end{landscape}
    \clearpage% Flush page
}
\lipsum % Text after
\end{document}
David Carlisle
  • 757,742
Martin Scharrer
  • 262,582
  • @MartinScharrer, what do you mean by "flushing potential tables beforehand"? I guess, in my case your solution doesn't work exactly because of that, but I am not expert enough to be sure about... – Py-ser Sep 03 '14 at 06:45
  • @Py-ser: I mean to flush the float buffer, e.g. place all processed but not yet placed tables or figures. You can force that using \clearpage. However, this creates a page break, so \afterpage{\clearpage} would be better. This forces the placement of any yet unplaced floats after the next normal page break. Not that this will lead to top placement (like the [t] optional argument of {table} would do) or a full float page (like [p]) if there are more or larger floats to be placed. As you can see, my code above uses \clearpage as the first command in \afterpage to do exactly that. – Martin Scharrer Sep 03 '14 at 14:02
  • @MartinScharrer, thanks! Does this still hold in a two-columns case? I can't manage to avoid blank breaking before the landscape page. – Py-ser Sep 04 '14 at 05:37
  • @Py-ser: This makes in more difficult. Not sure but I think the landscape page adds a page break of it's own. – Martin Scharrer Sep 04 '14 at 16:09
  • @MartinScharrer, thank you. I will make a new question then. – Py-ser Sep 05 '14 at 02:40
  • I posted a follow up question using this MWE because this MWE is exactly doing what I need, however I need a ROTATED pagenumber as well. See my question here: http://tex.stackexchange.com/q/258595/74646 – robert Aug 04 '15 at 10:23
  • I'm trying this technique, well all of them! The problem is that my table has a huge left margin on the landscaped page, and no right margin. How do i fix this and make it centered on the landscaped page from left to right? Note: It works fine if I have a left-to-right narrow table, but not with a long one (the whole point of landscaping it!). – travelingbones Nov 02 '16 at 17:56
  • 2
    So using this: \newgeometry{left=0.1cm,right=0.1cm,bottom=0.1cm,top=0.1cm} just before \begin{landscape} and \restoregeometry just after \end{landscape} worked! – travelingbones Nov 02 '16 at 18:12
  • @travelingbones your solution for margins caused the page number on the following page to disappear for me... – LShaver Mar 22 '17 at 20:28
  • @LShaver In IEEEtrans format that worked for me, in lncs fomat i'm having similar + other problems...haven't found a workaround (haven't really looked yet) – travelingbones Mar 23 '17 at 21:04
  • 1
    @LShaver this worked: \usepackage[pass]{geometry} \newgeometry{left=3cm,right=3cm,bottom=3cm,top=3cm} %% set the margins \begin{landscape}% Landscape page \centering \begin{table} ... \end{table}

    \end{landscape} \restoregeometry %% put margins back to default

    – travelingbones Mar 24 '17 at 20:55
  • 1
    @travelingbones that worked, with two caveats: the [pass] option threw an error, and wasn't necessary. Also, left/right and top/bottom follow the rest of the document, not the landscape orientation. – LShaver May 29 '17 at 15:35
  • @MartinScharrer thank you for the code. I'm having issues using commands like \toprule inside tabular with this set up: "The control sequence at the end of the top line of your error message was never \def'ed." Any idea what could cause the problem? – a_bet Mar 30 '20 at 17:47
  • @a_bet: AFAIK \toprule is defined by the booktabs package. Please check if it was loaded. – Martin Scharrer Apr 07 '20 at 07:00
32

You could use the sidewaystable environment from the rotating package; a little example:

\documentclass{article}
\usepackage{rotating}

\begin{document}
text text text text
\begin{sidewaystable}
  \centering
  \rule{3cm}{4cm}% to simulate a table
  \caption{A rotated table}
  \label{tab:test}
\end{sidewaystable}
text text text
\end{document}
Gonzalo Medina
  • 505,128
  • I have tried it but it produces the same result as with pdflscape. However, afterpage makes it work, as suggested in the link provided by Martin Scharrer. Thank you very much for your answer! – Marco May 25 '11 at 13:14
  • 1
    @Marco: sidewaystable and sidewaysfigure let the text flow. I'd be really interested in seeing an example in which the text doesn't flow. Could you please provide such a minimal example? – Gonzalo Medina May 25 '11 at 18:07
  • @GonzaloMedina, how can I let the table take one whole page and centered in that page, within the sidewaystable context? – Py-ser Sep 04 '14 at 09:51
  • It looks likt this: https://imgur.com/a/eOiAg – Martin Thoma Sep 21 '17 at 13:29
  • 1
    @GonzaloMedina It works, but the page has been placed at the end of the document after my bibliography. What to do ? – Duchamp Gérard H. E. Apr 29 '18 at 06:57
  • +1: The approach with the rotating package seems to work better with footnotes in the table (compared to pdflscape)! – strpeter Jul 31 '18 at 15:16
  • +1: a concise solution that requires only one additional package. – jboockmann Nov 04 '19 at 21:10
1
\documentclass{article}

\usepackage{lscape}

\begin{document}

% An extra wide table 
\begin{landscape}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}\hline

Object & Apple & Banana & Stone & Cake & Tree & Flower & House & Door & Car & Plane & Chair \\ \hline 

Quantity in Thousands & 35  &  25  & 23 & 33 & 43  & 52 & 64 & 75 & 86  & 94  & 122  \\ \hline 

\end{tabular}
\end{landscape}
\end{document}

%To this end, everything will be displayed in portrait format.\\
Leucippus
  • 1,636