0

I have a wide table, which I want to put in landscape, like in the example below. But it overlaps with the page header!

\documentclass[a4paper,12pt]{scrbook}

\usepackage[pass]{geometry}
\usepackage{pdflscape}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}
\setheadsepline{1pt}

\usepackage{lipsum}

\begin{document}

\chapter{first chapter}
\lipsum

\begin{landscape}
    \begin{tabular}{c|ccccccccccccccc}
        some wide table & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345  \\
    \end{tabular}
\end{landscape}

\end{document}

How can I avoid this? So far I only have part of a solution by reducing the page margins with

\newgeometry{
    top=3cm,
    bottom=1cm,
    left=1cm,
    right=1cm
    }

before the landscape environment and \restoregeometry after it. But then I have to define the top margin manually and it will not result in a consistent header with respect to the rest of the document.

  • 2
    Maybe try with something like \begin{landscape} \small \setlength{\tabcolsep}{4pt}. – leandriis Jun 13 '19 at 14:36
  • @leandriis that helps somewhat, but is not really what I am looking for. – Feodoran Jun 13 '19 at 15:55
  • 1
    If using a smaller font size in order to make the table fit between the margins does not suit your needs, could you please clarify on the desired result? – leandriis Jun 13 '19 at 21:01
  • 1
    what you mean with long table? From your MWE can be concluded, that your table is to wide even for landscape orientation. But it can be placed on one page, Do I'm right? – Zarko Jun 13 '19 at 21:27
  • Yes, the table is too wide for the margins. As a result it exceeds the right (top) margin, but still respects the left (bottom) margin. Therefore it is not centered on the page. I want to reduce the margins on both side, so that the table can be placed centered on the page. However, I want to keep the header placement consistent with the remaining document. – Feodoran Jun 14 '19 at 7:03
1

From your MWE can be concluded, that your table is not so long that you need more pages for it, but it is wider than width of the landscape oriented page. If my conclusion is correct, than you can use the tabular* table environment with prescribed width equal to text height and use macro \extracolsep{\fill}} for determining column separation. Using it you can use landscape orientation, but simpler/better is to use sidewaystable float defined in rotating package:

\documentclass[a4paper,12pt]{scrbook}
\usepackage[pass]{geometry}
% \usepackage{pdflscape}    % not used
\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}
\setheadsepline{1pt}
\usepackage{rotating}   % <--- new

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{lipsum}

\begin{document}

\chapter{first chapter}
\lipsum

\begin{sidewaystable}
\setlength\tabcolsep{0pt}
    \begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} c|ccccccccccccccc}
        some long table & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345  \\
    \end{tabular*}
\end{sidewaystable}

\end{document}

which gives:

enter image description here

(red lines indicate page layout)

  • Looks good. But what makes the table fit the page is actually not the sidewaystable, but redefining the colsep. You should include a comment about that. I guess changing the margins for that page should work independently from your solution? Also this makes me wonder what pdflscape is doing differently. Somehow it seems to put more space to the left of the table. – Feodoran Jun 14 '19 at 7:26
  • @Feodoran, sidewaystable is instead landscape, width is determined by prescribed table* width. This was obvious to me, however, you are right. I will add some more explanation. – Zarko Jun 14 '19 at 7:56
1

In the past I had problems with KOMA-Script and pdflscape. Therefore, with the answer of Jörg (the \newenvironment{rotatepage}) in this post Rotate single PDF page when viewing and the package hvfloat I found an "unconventional" way:

\documentclass[a4paper,12pt]{scrbook}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}
\setheadsepline{1pt}

\usepackage{lipsum}
\usepackage{hvfloat}
\usepackage{tabu}

\makeatletter
\newenvironment{rotatepage} %\newenvironment{Name}[Number]{Begin}{End}
{\if@twoside%
    \pagebreak[4]\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90} %
    \else%
    \clearpage\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 90}%
    \fi%
}%
{\if@twoside%
    \afterpage{\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}%
    \else%
    \afterpage{\global\pdfpageattr\expandafter{\the\pdfpageattr/Rotate 0}}%
    \fi%
} %
\makeatother %

\begin{document}

    \chapter{first chapter}
    \lipsum
     \vfill

    %saving the table in a box to be passed as argument to \hvfloat
    \savebox{\hvOBox}{%
%       \scalebox{0.9}{%changing the size of the table
%       \resizebox{23cm}{!} {%changing the size of the table
        \footnotesize %changing the font size of the table
       \begin{tabular}{c|ccccccccccccccc}
        some long table & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345  \\
       \end{tabular}}
%      }
     \begin{rotatepage}
    \hvFloat[capPos=r,objectAngle=90,capAngle=90,useOBox=true,]%
       {table}%
       {\hvOBox}%
       [wide table] %
       {wide table}
       {tab: wide table} 
     \end{rotatepage}
    \end{document}

Output changing font size:

enter image description here

  • @esdd, You are right. A workaround to control the table size is with scalebox or resizebox, see edited answer. – Ñako Jun 13 '19 at 20:33
  • scalebox and resizebox will lead to inconsistent font sizes throughout the document. Personally, I would not recommend to use them to scale tables. – leandriis Jun 13 '19 at 21:00
  • @leandriis, yes it could be a visual or formatting problem even more if there are many tables. Another possibility is to change directly the font size of the table (tables). Or may be the best way is to split the table. Have you any other ideas? – Ñako Jun 13 '19 at 21:53
1

If you insist on locally changing the margin instead of making the table itself narrower, you might want to use the changepage package and its adjustwidth environment:

enter image description here

\documentclass[a4paper,12pt]{scrbook}

\usepackage[pass]{geometry}
\usepackage{pdflscape}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}
\setheadsepline{1pt}

\usepackage{lipsum}
\usepackage{changepage} 

\begin{document}

\chapter{first chapter}
\lipsum

\begin{landscape}
\begin{adjustwidth}{-1cm}{-1cm} \centering
    \begin{tabular}{c|ccccccccccccccc}
        some wide table & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345 & 12345  \\
    \end{tabular}
\end{adjustwidth}
\end{landscape}

\end{document}

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.