17

It seems that neither \textwidth nor \textheight can force the table to fill the whole width.

\documentclass[dvips]{book}
\usepackage[a4paper,margin=20mm,showframe]{geometry}
\usepackage{lscape}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{longtable,array}

\begin{document}
\chapter{One}
\lipsum[1]
\section{One One}
\lipsum[2]

\pagestyle{empty}
\begin{landscape}
\begin{longtable}{|m{0.4\textheight-2\tabcolsep-1.5\fboxrule}|m{0.6\textheight-2\tabcolsep-1.5\fboxrule}|}
\hline
a & b\\\hline
c & d\\\hline
\end{longtable}
\end{landscape}
\pagestyle{plain}

\lipsum[3]
\end{document}

EDIT 1:

I made a correction in the column width, i.e., changing 2\fboxrule to 1.5\fboxrule. The former calculation is wrong because the rule between 2 columns should NOT be calculated twice. I slipped a little here.

And I got an output as follows:

alt text


EDIT 2: It's my real scenario (as opposed to the minimal code)

\documentclass[dvipsnames,rgb,dvips]{book}

\usepackage[a4paper,margin=20mm,showframe]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{calc}
\usepackage{ltablex}
\usepackage{lscape}

\newcounter{No}
\renewcommand{\theNo}{\stepcounter{No}\arabic{No}}
\newenvironment{MyTable}[4]%
{%
    \newcolumntype{A}[1]%
    {%
        >{%
            \begin{minipage}%
                {%
                    ##1\textwidth-2\tabcolsep-1.5\arrayrulewidth%
                }%
                \vspace{\tabcolsep}%
         }%
         c%
        <{\vspace{\tabcolsep}\end{minipage}}%
    }%
    \setcounter{No}{0}%comment out this if you want to continuous numbering for all tables.
    \begin{longtable}%
    {%
            |>{\scriptsize\centering\theNo}A{#1}<{}%
            |>{}A{#2}<{\centering\input{\jobname.tmp}}%
            |>{\centering\lstinputlisting{\jobname.tmp}}A{#3}<{}%
            |>{\scriptsize\arraybackslash}A{#4}<{}%
            |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\newcommand{\Comment}[1]{& & & #1\\\hline}


\usepackage{listings}
\lstset{%
language={PSTricks},
basicstyle=\ttfamily\scriptsize,%
keywordstyle=\color{blue}%,
%backgroundcolor=\color{yellow!30}%
}
\usepackage{fancyvrb}


\def\MyRow{%        
        \VerbatimEnvironment%
        \begin{VerbatimOut}{\jobname.tmp}%
}

\def\endMyRow{%
        \end{VerbatimOut}%      
}



\usepackage{pstricks,pst-node}
\newpsstyle{gridstyle}{%
gridwidth=0.4pt,%default: 0.8pt
gridcolor=Red!20,%default: black
griddots=0,%default: 0 
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=Blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=Green!20,%default: gray
subgriddots=0%default: 0
}

\usepackage{lipsum}

\begin{document}
\chapter{Introduction to PSTricks}
\lipsum[1]

\section{At a glance galleries}
\lipsum[1-5]

%Landscape starts here.
%\pagestyle{empty}
\begin{landscape}
\thispagestyle{empty}
\begin{MyTable}{0.05}{.25}{0.4}{0.3}%
%=============
\begin{MyRow}
\pspicture*[showgrid](4,4)
\pnode(1,1){A}
\pnode(3,3){B}
\ncline{A}{B}
\endpspicture
\end{MyRow}
\Comment{\lipsum[1]}
%=============
\begin{MyRow}
\begin{pspicture}[showgrid](4,3)
\psframe*[linecolor=red!30](3,2)
\end{pspicture}
\end{MyRow}
\Comment{\lipsum[2]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=green!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[3]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=yellow!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[4]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=Maroon!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[5]}
%=============
\end{MyTable}
%Landscape stops here.
\end{landscape}
%\pagestyle{plain}

\section{Node}
\lipsum[1-5]
\end{document}

Unfortunately, \arrayrulewidth does not work.


EDIT 3:

dvips has been added for both code snippets above. The \arrayrulewidth still cannot work the way we want.

| improve this question | | | | |
  • do you run latex or pdflatex? – user2478 Dec 24 '10 at 6:57
  • @Herbert, I always use latex.exe because I use PSTricks package. – xport Dec 24 '10 at 7:02
  • then use always the dvips option in the document header to tell geometry how it should pass the page dimensions to the program dvips (see my header) – user2478 Dec 24 '10 at 7:16
4

Here is my solution

\documentclass[dvipsnames,rgb,dvips]{book}

\usepackage[a4paper,margin=20mm,showframe]{geometry}
\usepackage{longtable}
\usepackage{array}
\usepackage{calc}
\usepackage{ltablex}
\usepackage{lscape}
\usepackage{ragged2e}

\newcounter{No}
\renewcommand{\theNo}{\stepcounter{No}\arabic{No}}
\newcolumntype{A}[1]{%
  >{\vspace*{\medskipamount}\Centering}
  p{#1\linewidth-2\tabcolsep-2\arrayrulewidth}
  <{\smallskip}}
\newenvironment{MyTable}[4]%
  {\setcounter{No}{0}%comment out this if you want to continuous numbering for all tables.
   \begin{longtable}{%
            |>{\scriptsize\theNo}A{#1}<{}%
            |>{}l<{\minipage[t]{#2\linewidth-2\tabcolsep-2\arrayrulewidth}
                   \vspace{0pt}\input{\jobname.tmp}\endminipage}%
            |>{\Centering\lstinputlisting{\jobname.tmp}}A{#3}<{}%
            |>{\scriptsize\arraybackslash}A{#4}<{}%
            |%
    }%
    \hline\ignorespaces%
}%
{%
    \end{longtable}%
}

\newcommand{\Comment}[1]{& & & #1\\\hline}

\usepackage{listings}
\lstset{%
language={PSTricks},
basicstyle=\ttfamily\scriptsize,%
keywordstyle=\color{blue}%,
%backgroundcolor=\color{yellow!30}%
}
\usepackage{fancyvrb}
\def\MyRow{%        
        \VerbatimEnvironment%
        \begin{VerbatimOut}{\jobname.tmp}}

\def\endMyRow{\end{VerbatimOut}}

\usepackage{pstricks,pst-node}
\newpsstyle{gridstyle}{%
gridwidth=0.4pt,%default: 0.8pt
gridcolor=Red!20,%default: black
griddots=0,%default: 0 
%
gridlabels=3pt,%default: 10pt
gridlabelcolor=Blue,%default: black
%
subgriddiv=5,%default: 5
subgridwidth=0.2pt,%default: 0.4pt
subgridcolor=Green!20,%default: gray
subgriddots=0%default: 0
}

\usepackage{lipsum}

\begin{document}
\chapter{Introduction to PSTricks}
\lipsum[1]

\section{At a glance galleries}
\lipsum[1-5]

%Landscape starts here.
%\pagestyle{empty}
\begin{landscape}
\noindent
\rule{\linewidth}{4pt}

\thispagestyle{empty}
\begin{MyTable}{0.05}{.25}{0.4}{0.3}%
%=============
\begin{MyRow}
\pspicture[showgrid](4,4)
\pnode(1,1){A}
\pnode(3,3){B}
\ncline{A}{B}
\endpspicture
\end{MyRow}
\Comment{\lipsum[1]}
%=============
\begin{MyRow}
\begin{pspicture}[showgrid](4,3)
\psframe*[linecolor=red!30](3,2)
\end{pspicture}
\end{MyRow}
\Comment{\lipsum[2]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=green!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[3]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=yellow!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[4]}
%=============
\begin{MyRow}
\pspicture[showgrid](4,3)
\psframe*[linecolor=Maroon!30](3,2)
\endpspicture
\end{MyRow}
\Comment{\lipsum[5]}
%=============
\end{MyTable}
%Landscape stops here.
\end{landscape}
%\pagestyle{plain}

\section{Node}
\lipsum[1-5]
\end{document}
| improve this answer | | | | |
  • @Herbert, I have to submit my real scenario because the table I used is very tricky (there is a nested minipage inside each cell). Please kindly to see again my edit 2 above. – xport Dec 24 '10 at 7:16
  • @Herbert, which one is the correct one: 2\arrayrulewidth or 1.5\arrayrulewidth ? – xport Dec 24 '10 at 8:05
  • 1
    depends to what you want to describe. For a minipage inside a cell -2, for a cell in a tabular header it is one time 2 and all the other 1. For n cells you have n+1 lines. However, for a minipage inside one cell you can choose \columnwidth, then it is correct. – user2478 Dec 24 '10 at 8:09
  • 1
    @xport-is-sleeping: Your decision. I do not like that. I would use a new letter for another columntype. However, it is possible to overwrite column definitions and it makes no real sense to define a new columntype when you use it only once in the environment, because you can use the definition directly. – user2478 Dec 24 '10 at 9:19
  • 1
    no, but you can it overwrite it with \newcolumntype – user2478 Dec 24 '10 at 9:56
36

use always \linewidth inside the landscape environment and not \textwidth

| improve this answer | | | | |
  • For the sake of completeness, could you give me a comment whether or not this calculation ##1\linewidth-2\tabcolsep-1.5\fboxrule is correct? – xport Dec 24 '10 at 7:29
  • Please wait for 1 hour, I have a telephone call. I am sorry. – xport Dec 24 '10 at 7:30
  • I edited my code, see above – user2478 Dec 24 '10 at 8:10
1

Disclaimer: This solution is intended for KOMA-script's classes only.


The landscape environment of the pdflscape package is indeed the key for creating sideway floats, as shown in Herbert's solution.
Indeed, it rotates the float but keeps head- and footnotes correctly positioned. Moreover, it automatically rotates the relevant page in the pdf, in order to make easy to read the document on screen.

However, as noted in KOMA-Script documentation in §16.6:

Package lscape defines an environment landscape to set the page contents but not head and foot landscape. Inside this environment it changes \textheight to the value of \textwidth, but it does not change \textwidth to the former value of \textheight. This is inconsistent.

The solution for KOMA-script's classes is thus to also load the scrhack package, after pdflscape.

enter image description here

enter image description here


\documentclass{scrartcl}
    %needed for this solution
    \usepackage{pdflscape}
    \usepackage{scrhack}

    %mainstream packages for tables
    \usepackage{tabularx}
    \usepackage{booktabs}

    %for illustration purpose
    \usepackage{lipsum}
    \usepackage{showframe}
\begin{document}
    \lipsum[1-2]

    \begin{landscape}%
        \captionof{table}[Caption for LoT]{Caption of the table}%
        \small%
        \noindent%
        \begin{tabularx}{\textheight}{lXX}
        \toprule
            \emph{Lorem}
            &
            \textbf{Ipsum dolor}
            &
            \textbf{Sit amet}
        \\
        \midrule
            \emph{Consectetur adipiscing}
            &
            In sed facilisis lacus, consectetur volutpat nulla. Praesent quis vulputate urna.
            &
            Suspendisse non dui fermentum, convallis velit non, consequat diam.
        \\
            \emph{In at sem eros.}
            &
            Maecenas tellus eros, porttitor non varius eget, porttitor eu ipsum.
            &
            Etiam accumsan pharetra convallis. 
        \\
        \bottomrule
        \end{tabularx}%
    \end{landscape}

    \lipsum[3-4]
\end{document}
| improve this answer | | | | |

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.