3

This may be similar to this question: How to make a tabular in a header ignore the environment set by the currently processed longtable

I don't really manage to get an answer from it. I have a tabular environment in my fancyhdr which works well, but when I do arraystretch or extrarowheight before a longtable the header also gets stretched which I do niot want. I've tried to group the longtable but nothing seems to work. I will provide more code if needed.

I have a longtable:

\begingroup
\setlength{\extrarowheight}{0.5cm}
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
%CONTENT
\end{longtable}
\endgroup

Here's usepackages and other configurations

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[12pt, twoside, a4paper]{article} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions
\usepackage[utf8]{inputenc}% latin1  utf8
\usepackage[T1]{fontenc}
\usepackage{amsmath} % Required for equation customization
\usepackage{amssymb} % Required to include mathematical symbols 
\usepackage{xcolor} % Required to specify colors by name
\usepackage[norsk]{babel}
\usepackage{tabularx} %Adds the X possibility to tabular
\usepackage{longtable}
\usepackage{ltxtable}
\usepackage{booktabs}
\usepackage{lastpage} % Required to print the total number of pages
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fancyhdr} % Required to customize headers
\usepackage[pagebackref=false]{hyperref}
\usepackage{color}
\usepackage{appendix}
\usepackage{nomencl}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{grffile}
\usepackage{pdfpages} 
\usepackage[left=1.5cm,right=1.5cm,top=5cm,bottom=4.0cm,marginparwidth=0pt, headheight=2.5cm ]{geometry} % Adjust page margins
%\usepackage{showframe} % Show margins on page


\pagestyle{fancy}\fancyhf{} % Use the custom header specified below
\renewcommand{\headrulewidth}{0pt} % Remove the default horizontal rule under the header

\setlength{\parindent}{0cm} % Remove paragraph indentation
\newcommand{\tab}{\hspace*{2em}} % Defines a new command for some horizontal space
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\tolerance = 5000     %3000
\hbadness = \tolerance
\pretolerance = 2000  %1000

\input{./Header/Header}

\begin{document}
    \def\contentsname{Innholdsfortegnelse} %Dette blir navnet i Innholdsfortegnelsen
\tableofcontents
\newpage

%----------------------------------------------------------------------------------------
%   REVISJONSHISTORIKK
%----------------------------------------------------------------------------------------

\input{./Revisjonshistorikk/Revisjonshistorikk} % THE LONGTABLE IS PLACE IN HERE

\end{document}

This is the result with \renewcommand\arraystretch{1.0} before the longtable. No arraystretch

This is the result with \renewcommand\arraystretch{1.5} before the longtable.

arraystretch = 1.5

4
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. You could put the following in your header effectively setting up a local environment which has a defined \extrarowheight of 0pt: \bgroup\setlength{\extrarowheight}{0pt}<your tabular>\egroup
    – Skillmon
    Jan 14, 2018 at 11:11
  • And please make your MWE self contained. No one of us has the file ./Header/Header and no one has ./Revisjonshistorikk/Revisjonshistorikk.
    – Skillmon
    Jan 14, 2018 at 11:13
  • First, thank you for editing my question and providing a MWE for everybody. Your solution worked like a charm. Should I still update the question with a MWE? Thanks again!
    – Cobse
    Jan 14, 2018 at 15:17
  • You should in general always add a MWE to your question (there are a few exceptions to this rule, but if you ask a question that doesn't need one, you should be absolutely sure about this). Note that my answer doesn't provide a MWE. A MWE should always start at \documentclass and end at \end{document} including all necessary packages, but no more than that. See this link for a guideline for MWEs.
    – Skillmon
    Jan 14, 2018 at 18:33

2 Answers 2

3

I used some dummy stuff to replace your contents which no one of us has. The following uses the approach I proposed in my comment. Namely I put setlength\extrarowheight{0pt} or \def\arraystretch{1} explicitly in the header inside a \bgroup...\egroup-group. This way the specified extra space of the longtable doesn't affect the header.

Using \extrarowheight

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[12pt, twoside, a4paper]{article} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions
\usepackage[utf8]{inputenc}% latin1  utf8
\usepackage[T1]{fontenc}
\usepackage{amsmath} % Required for equation customization
\usepackage{amssymb} % Required to include mathematical symbols 
\usepackage{xcolor} % Required to specify colors by name
\usepackage[norsk]{babel}
\usepackage{tabularx} %Adds the X possibility to tabular
\usepackage{longtable}
\usepackage{ltxtable}
\usepackage{booktabs}
\usepackage{lastpage} % Required to print the total number of pages
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fancyhdr} % Required to customize headers
\usepackage[pagebackref=false]{hyperref}
\usepackage{color}
\usepackage{appendix}
\usepackage{nomencl}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{grffile}
\usepackage{pdfpages} 
\usepackage[left=1.5cm,right=1.5cm,top=5cm,bottom=4.0cm,marginparwidth=0pt, headheight=2.5cm ]{geometry} % Adjust page margins
%\usepackage{showframe} % Show margins on page


\pagestyle{fancy}\fancyhf{} % Use the custom header specified below
\renewcommand{\headrulewidth}{0pt} % Remove the default horizontal rule under the header

\setlength{\parindent}{0cm} % Remove paragraph indentation
\newcommand{\tab}{\hspace*{2em}} % Defines a new command for some horizontal space
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\tolerance = 5000     %3000
\hbadness = \tolerance
\pretolerance = 2000  %1000

%\input{./Header/Header}
\lhead{%
  \bgroup
  \setlength\extrarowheight{0pt}%
  \begin{tabular}{lcl}
    \hline
    This & is & my\\
    awesome&looking&header\\
    \hline
  \end{tabular}%
  \egroup}

\begin{document}
    \def\contentsname{Innholdsfortegnelse} %Dette blir navnet i Innholdsfortegnelsen
\tableofcontents
\newpage

%----------------------------------------------------------------------------------------
%   REVISJONSHISTORIKK
%----------------------------------------------------------------------------------------

%\input{./Revisjonshistorikk/Revisjonshistorikk} % THE LONGTABLE IS PLACE IN HERE
\begingroup
\setlength{\extrarowheight}{0.5cm}
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
  \hline
  this & is & some\\
  \hline
  dummy & content& just\\
  to & see & the\\
  table&formatting&of\\
  this&&\\
  \hline
\end{longtable}
\endgroup

\end{document}

enter image description here

Using \def\arraystretch{2}

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[12pt, twoside, a4paper]{article} % Use A4 paper with a 12pt font size - different paper sizes will require manual recalculation of page margins and border positions
\usepackage[utf8]{inputenc}% latin1  utf8
\usepackage[T1]{fontenc}
\usepackage{amsmath} % Required for equation customization
\usepackage{amssymb} % Required to include mathematical symbols 
\usepackage{xcolor} % Required to specify colors by name
\usepackage[norsk]{babel}
\usepackage{tabularx} %Adds the X possibility to tabular
\usepackage{longtable}
\usepackage{ltxtable}
\usepackage{booktabs}
\usepackage{lastpage} % Required to print the total number of pages
\usepackage{graphicx}
\usepackage{varioref}
\usepackage{multirow}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fancyhdr} % Required to customize headers
\usepackage[pagebackref=false]{hyperref}
\usepackage{color}
\usepackage{appendix}
\usepackage{nomencl}
\usepackage{verbatim}
\usepackage{cleveref}
\usepackage{grffile}
\usepackage{pdfpages} 
\usepackage[left=1.5cm,right=1.5cm,top=5cm,bottom=4.0cm,marginparwidth=0pt, headheight=2.5cm ]{geometry} % Adjust page margins
%\usepackage{showframe} % Show margins on page


\pagestyle{fancy}\fancyhf{} % Use the custom header specified below
\renewcommand{\headrulewidth}{0pt} % Remove the default horizontal rule under the header

\setlength{\parindent}{0cm} % Remove paragraph indentation
\newcommand{\tab}{\hspace*{2em}} % Defines a new command for some horizontal space
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\tolerance = 5000     %3000
\hbadness = \tolerance
\pretolerance = 2000  %1000

%\input{./Header/Header}
\lhead{%
  \bgroup
  \def\arraystretch{1}%
  \begin{tabular}{lcl}
    \hline
    This & is & my\\
    awesome&looking&header\\
    \hline
  \end{tabular}%
  \egroup}

\begin{document}
    \def\contentsname{Innholdsfortegnelse} %Dette blir navnet i Innholdsfortegnelsen
\tableofcontents
\newpage

%----------------------------------------------------------------------------------------
%   REVISJONSHISTORIKK
%----------------------------------------------------------------------------------------

%\input{./Revisjonshistorikk/Revisjonshistorikk} % THE LONGTABLE IS PLACE IN HERE
\begingroup
\def\arraystretch{2}%
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
  \hline
  this & is & some\\
  \hline
  dummy & content& just\\
  to & see & the\\
  table&formatting&of\\
  this&&\\
  \hline
\end{longtable}
\endgroup

\end{document}

enter image description here

2

better than use \arraystretch is add vertical space before and after cells content. this possibility offer makcell package. unfortunately macro \makegapedcells which do this, is not compatible with `m{...}˙column types. however, Ulrike Fischer is provide patch for this.

a mwe (for it i remove for this case all unnecessary packages from your document preamble):

\documentclass[12pt, twoside, a4paper]{article}
\usepackage{array, booktabs, longtable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\usepackage{makecell}% <-- added
\makeatletter        % <-- patch for m columns
\renewcommand\mcell@classz{\@classx
   \@tempcnta \count@
   \prepnext@tok
   \@addtopreamble{%\mcell@mstyle
      \ifcase\@chnum
         \hfil
         \mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
         \hskip1sp
         \mcell@agape{\d@llarbegin\insert@column\d@llarend}\hfil \or
         \hfil\hskip1sp
         \mcell@agape{\d@llarbegin \insert@column\d@llarend}\or
         \mcell@agape{$\vcenter
         \@startpbox{\@nextchar}\insert@column\@endpbox$}\or
         \mcell@agape{\vtop
         \@startpbox{\@nextchar}\insert@column\@endpbox}\or
         \mcell@agape{\vbox
         \@startpbox{\@nextchar}\insert@column\@endpbox}%
      \fi
      \global\let\mcell@left\relax\global\let\mcell@right\relax
    }\prepnext@tok}
\makeatother
\setcellgapes{7pt}

\usepackage{lipsum} % for dummy text


\begin{document}

\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
  \hline
1 & some text & \lipsum*[11]\\
  \hline
2 & some text & \lipsum*[11]\\
  \hline
\end{longtable}

\begingroup
\makegapedcells
\begin{longtable}{|C{1cm} | L{3cm} | L{12.6cm}|}
  \hline
1 & some text & \lipsum*[11]\\
  \hline
2 & some text & \lipsum*[11]\\
  \hline
\end{longtable}
\endgroup

\end{document}

enter image description here

addedndum: However, i would design this table differently

\documentclass[12pt,twoside,a4paper]{article}
\usepackage{booktabs, longtable}

\usepackage{lipsum} % for dummy text
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
\begin{longtable}{p{1cm}  p{2cm}  p{\dimexpr\linewidth-3cm-6\tabcolsep}}
    \toprule
A   & B         & C             \\
    \midrule
1   & some text & \lipsum*[11]  \\
    \addlinespace
2   & some text & \lipsum*[11]  \\
  \bottomrule
\end{longtable}
\end{document}

enter image description here

3
  • This seems a lot more complicated than the solution above? Why is this better?
    – Cobse
    Jan 14, 2018 at 15:19
  • if you not observe difference, than this answer is not for you. However, i would design this table differently (without patch for m columns ...), see addendum.
    – Zarko
    Jan 14, 2018 at 18:17
  • Since you didn't answer it properly then it's not better then, or? I agree on the design.
    – Cobse
    Jan 15, 2018 at 7:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .