1

I have a problem. I am creating MSDS sheets using LaTeX, (actually a web-application that creates a LaTeX code).

The basic setup of the sheet is such that for each section (there are 16 sections) a mdframed environment (named boxtype1, courtesy of the internet) contains various longtables and "sections*".

I included a figure of what is happening, and also a LaTeX code-sample of one of the sections... I know it's not the most simple one I could have managed but it is a clear example of what is happening.

Strange and irritating page-breaks

%%% Document info
\documentclass[11pt]{report}
\usepackage{geometry}
\geometry{
 a4paper,
 total={210mm,297mm},
 left=20mm,
 right=20mm,
 top=30mm,
 bottom=20mm}
\usepackage{fancyhdr}
\usepackage[parfill]{parskip}       % Activate to begin paragraphs with an empty line rather than an indent

\textheight=225mm       %
\headsep=25mm         %
%

%%% Math/Fonts/Language setup -- unicode rules
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage[version=3]{mhchem} 

% Language stuff
\usepackage[icelandic]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% Image stuff and output handling
\usepackage{pstricks}
\usepackage{color}
\definecolor{blue}{HTML}{0047ab}
\usepackage{epstopdf}

% Tikz and mdframed for section frames, as well as mdframed
\usepackage[framemethod=tikz]{mdframed}
\mdfsetup{font=\small}
\usepackage{longtable}

% Headers and footers
\usepackage{fancyhdr}

\pagestyle{fancy} % enable fancy page style
\renewcommand{\footrulewidth}{0.5pt}

\fancyhf{} % clear header and footer

\fancyhead[L]{ \textbf{{\huge Öryggisblað (MSDS)}\\ \vspace{2mm}
Samkvæmt reglugerð: 750/2008 (REACH) \vspace{2mm}}}

\fancyhead[R]{ \textbf{{Stofnað: 21.05.15}\\ \vspace{2mm}
Síðast breytt: 21.08.15  \vspace{2mm}}}

\fancyfoot[R]{{Síða\ \thepage\ af\ \pageref{LastPage}}}

% Paragraph settings and fontfamily
\setlength{\parskip}{1em}
\renewcommand{\baselinestretch}{1.0}
\renewcommand*{\familydefault}{\sfdefault}


\def\arraystretch{1.5}
\newenvironment{boxtype1}[1]
  {%
  \begin{mdframed}[
    linewidth=.5,
    everyline=true,
    backgroundcolor=gray!2,
    linecolor=black,
    middlelinewidth=0.5pt,
    font=\sffamily\small,
    splittopskip=30pt,
    splitbottomskip=20pt,
    skipabove = 25pt,
    innertopmargin = 30pt,
    innerbottommargin = 20pt,
     singleextra={
      \node[
        overlay,
        fill=white,
        anchor=west,
        font=\sffamily\large,
        inner xsep=10pt
      ] at ([xshift=10pt]O|-P) {\textbf{\color{blue} #1}};
      },
      firstextra={
      \node[
        overlay,
        fill=white,
        anchor=west,
        font=\sffamily\large,
        inner xsep=10pt
      ] at ([xshift=10pt]O|-P) {\textbf{\color{blue} #1}};
      },
    secondextra={
      \node[
        overlay,
        fill=white,
        anchor=west,
        font=\sffamily\large,
        inner xsep=10pt
      ] at ([xshift=10pt]O|-P) {\textbf{\color{blue} #1 framhald}};
      },
    middleextra={
      \node[
        overlay,
        fill=white,
        anchor=west,
        font=\sffamily\large,
        inner xsep=10pt
      ] at ([xshift=10pt]O|-P) {\textbf{\color{blue} #1 framhald}};
      }
  ]
  }
  {\end{mdframed}}


\begin{document}

\begin{boxtype1}{12. Vistfræðilegar upplýsingar}

    \textbf{\color{blue}12.1. Eiturhrif}

    \begin{longtable}{p{0.28\linewidth}p{0.65\linewidth}}
         \textbf{\color{black}Aðrar vistfræðilegar uppl.:}  &  Eitrað vatnalífverum, getur valdið neikvæðum langtíma áhrifum í vatnaumhverfi. Forðist losun út í umhverfið.\\
    \end{longtable}

    \begin{longtable}{p{0.25\linewidth}|p{0.12\linewidth}p{0.12\linewidth}p{0.12\linewidth}p{0.12\linewidth}p{0.12\linewidth}}
        \caption*{\textbf{Tafla 12.1 - Þekkt eitrunarmörk innihaldsefna}}\\

        \textbf{Efni} & \textbf{Teg. gildis} & \textbf{Gildi} & \textbf{Tími} & \textbf{Tegund} & \textbf{Undirtegund}\\
        \hline
        Kúmen vetnisperoxíð (80-15-9) & LC50 & 3,9 mg/l & 96 klst & Fiskur & Oncorhynchus mykiss\\
        Kúmen vetnisperoxíð (80-15-9) & EC50 & 18 mg/l & 48 klst & Daphnia & Daphnia magna\\
        Kúmen vetnisperoxíð (80-15-9) & EC50 & 3,1 mg/l & 72 klst & Þörungar & Pseudokirchnerella subcapitata\\
        2-Hýdroxýetýl metakrýlat (868-77-9) & LC50 & 227 mg/l & 96 klst & Fiskur & Pimephales promelas\\
        2-Hýdroxýetýl metakrýlat (868-77-9) & EC50 & 345 mg/l & 72 klst & Þörungar & Pseudokirchnerella subcapitata\\
        2-Hýdroxýetýl metakrýlat (868-77-9) & EC50 & 380 mg/l & 48 klst & Daphnia & Daphnia magna\\
        2-Hýdroxýetýl metakrýlat (868-77-9) & NOEC & 160 mg/l & 72 klst & Þörungar & Pseudokirchnerella subcapitata\\
        2-Hýdroxýetýl metakrýlat (868-77-9) & NOEC & 24,1 mg/l & 21 dagur & Daphnia & Pseudokirchnerella subcapitata\\
        Akrýlsýra (79-10-7) & LC50 & 27 mg/l & 96 klst & Fiskur & Oncorhynchus mykiss\\
        Akrýlsýra (79-10-7) & NOEC & 0,13 mg/l & 21 dagur & Daphnia & Daphnia magna\\
        Akrýlsýra (79-10-7) & EC50 & 0,13 mg/l & 72 klst & Þörungar & Desmodesmus subspicatus\\
        Maleic sýra (110-16-7) & LC50 & > 245 mg/l & 48 klst & Fiskur & Leuciscus idus\\
        Maleic sýra (110-16-7) & EC50 & 42,81 mg/l & 48 klst & Daphnia & Daphnia magna\\
        Metakrýlsýra (79-41-4) & LC50 & 100 - 180 mg/l & 96 klst & Fiskur & Danio rerio\\
        Metakrýlsýra (79-41-4) & EC50 & > 8,2 mg/l &  & Þörungar & \\
        Metakrýlsýra (79-41-4) & EC50 & > 130 mg/l & 48 klst & Daphnia & Daphnia magna\\
        Hýdroxýprópýl metakrýlat (27813-02-1) & LC50 & 493 mg/l & 48 klst & Fiskur & Leuciscus idus melanotus\\
    \end{longtable}

    \textbf{\color{blue}12.2. Þrávirkni og niðurbrjótanleiki}

    \begin{longtable}{p{0.28\linewidth}p{0.65\linewidth}}
        \textbf{\color{black}Hegðan í umhverfinu:}  &  Engar upplýsingar tiltækar.\\
    \end{longtable}

    \begin{longtable}{p{0.25\linewidth}|p{0.19999999999999998\linewidth}p{0.19999999999999998\linewidth}p{0.19999999999999998\linewidth}}
        \caption*{\textbf{Upplýsingar um niðurbrjótanleika innihaldsefna}}\\

        \textbf{Heiti} & \textbf{Aðferð} & \textbf{Niðurstaða} & \textbf{Niðurbrjótanleiki}\\
        \hline
        Kúmen vetnisperoxíð (80-15-9) & OECD 301 B & 0 \% & Enginn\\
        2-Hýdroxýetýl metakrýlat (868-77-9) & OECD 301 C & 92 - 100 \% & Mikill\\
        Akrýlsýra (79-10-7) & OECD 301 D & 81 \% & Mikill\\
        Maleic sýra (110-16-7) & OECD 301 B & 97,08 \% & Mikill\\
        Metakrýlsýra (79-41-4) & OECD 301 D & 86 \% & Mikill\\
        Hýdroxýprópýl metakrýlat (27813-02-1) & OECD 301 E & 94,2 \% & Mikill\\
    \end{longtable}

    \textbf{\color{blue}12.3. Uppsöfnun í lífverum / 12.4. Hreyfanleiki í jarðvegi}\vspace{-2mm}

    \begin{longtable}{p{0.28\linewidth}p{0.65\linewidth}}
        \textbf{\color{black}Hreyfanleiki í jarðvegi:}  &  Enginn, eftir storknun.\\
    \end{longtable}

    \begin{longtable}{p{0.25\linewidth}|p{0.12\linewidth}p{0.12\linewidth}p{0.12\linewidth}p{0.12\linewidth}p{0.12\linewidth}}
        \caption*{\textbf{BCF og Log K$_{ow}$ stuðlar}}\\

        \textbf{Efni} & \textbf{Log K$_{ow}$} & \textbf{BCF} & \textbf{Hitastig} & \textbf{Aðferð} & \textbf{Tegund}\\
        \hline
        Kúmen vetnisperoxíð (80-15-9) &  & 9,1 &  & OECD 305 & Reiknað gildi\\
        Kúmen vetnisperoxíð (80-15-9) & 2,16 &  &  &  & \\
        Akrýlsýra (79-10-7) &  & 3,16 &  &  & \\
        Akrýlsýra (79-10-7) & 0,46 &  & 25 $^\circ$C & OECD 107 & \\
        Maleic sýra (110-16-7) & -1,3 &  & 20 $^\circ$C & OECD 107 & \\
        Metakrýlsýra (79-41-4) & 0,93 &  &  &  & \\
        Hýdroxýprópýl metakrýlat (27813-02-1) & 0,97 &  &  &  & \\
    \end{longtable}

    \textbf{\color{blue}12.5. Niðurstöður úr mati á PBT- og vPvB-eiginleikum}\vspace{-2mm}

    \begin{longtable}{p{0.28\linewidth}p{0.65\linewidth}}
        \multicolumn{2}{p{0.93\linewidth}}{Ekkert innihaldsefna þessarar blöndu fellur undir viðmið PBT eða vPvB. Efnablandan flokkast því ekki sem SVHC (Substances of Very High Concern).}\\
    \end{longtable}\vspace{-5mm}

    \textbf{\color{blue}12.6. Önnur skaðleg áhrif}\vspace{-2mm}

    \begin{longtable}{p{0.28\linewidth}p{0.65\linewidth}}
         \multicolumn{2}{p{0.93\linewidth}}{Engin gögn tiltæk.}\\
    \end{longtable}\vspace{-5mm}

\end{boxtype1}


\label{LastPage}

\end{document}

And yes... I know the code does not look good, and also that there are some strangely accurate numbers around. But this is just parsed with jQuery and printed, so I have not been focusing on code-beuty.

Thanks in advance Benedikt

EDIT by cfr

This is an attempt to produce a slightly less maximal minimal example. If the OP considers it to accurately reflect the problem, s/he might want to use it as the basis for further edits.

In this code, I use different colours to help clarify the role of various parts of the definition of the boxtype1 environment. Obviously, this is just for illustration - nobody would actually change the colours this way other than for debugging purposes ;). I've also used the current bounding box rather than the O |- P syntax which I find obscure since you have to know how the package defines O and P.

\documentclass[a4paper]{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{longtable,array}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\newenvironment{boxtype1}[1]
{%
  \begin{mdframed}[
    linewidth=.5,
    everyline=true,
    backgroundcolor=gray!2,
    linecolor=black,
    middlelinewidth=0.5pt,
    font=\sffamily\small,
    splittopskip=30pt,
    splitbottomskip=20pt,
    skipabove = 25pt,
    innertopmargin = 30pt,
    innerbottommargin = 20pt,
    firstextra={
      \node[
      overlay,
      fill=white,
      anchor=west,
      font=\sffamily\large,
      inner xsep=10pt
      ] at ([xshift=10pt]current bounding box.north west) {\textbf{\color{orange} #1}};
    },
    secondextra={
      \node[
      overlay,
      fill=white,
      anchor=west,
      font=\sffamily\large,
      inner xsep=10pt
      ] at ([xshift=10pt]current bounding box.north west) {\textbf{\color{red} #1 framhald}};
    },
    middleextra={
      \node[
      overlay,
      fill=white,
      anchor=west,
      font=\sffamily\large,
      inner xsep=10pt
      ] at ([xshift=10pt]current bounding box.north west) {\textbf{\color{green} #1 framhald}};
    }
  ]
}
{\end{mdframed}}

\begin{document}
\begin{boxtype1}{12. Vistfræðilegar upplýsingar}
  \textbf{\color{blue}12.1. Eiturhrif}\vspace{-2mm}
  \begin{longtable}{p{0.28\linewidth}p{0.65\linewidth}}
    \textbf{\color{black}Aðrar vistfræðilegar uppl.:} & Eitrað vatnalífverum, getur valdið neikvæðum langtíma áhrifum í vatnaumhverfi. Forðist losun út í umhverfið.\\
  \end{longtable}

  \begin{longtable} {>{\hskip 0pt}p{0.25\linewidth}|*{5}{>{\hskip 0pt}p{0.12\linewidth}}}
      \caption*{\textbf{Tafla 12.1 - Þekkt eitrunarmörk innihaldsefna}}\\
      \textbf{Efni}&\textbf{Teg. gildis}&\textbf{Gildi}&\textbf{Tími}&\textbf{Tegund}&\textbf{Undirtegund}\\
      \hline
      Kúmen vetnisperoxíð (80-15-9)&LC50&3,9 mg/l&96 klst&Fiskur&Oncorhynchus mykiss\\
      Kúmen vetnisperoxíð (80-15-9)&EC50&18 mg/l&48 klst&Daphnia&Daphnia magna\\
      Kúmen vetnisperoxíð (80-15-9)&EC50&3,1 mg/l&72 klst&Þörungar&Pseudokirchnerella subcapitata\\
      2-Hýdroxýetýl metakrýlat (868-77-9)&LC50&227 mg/l&96 klst&Fiskur&Pimephales promelas\\
      2-Hýdroxýetýl metakrýlat (868-77-9)&EC50&345 mg/l&72 klst&Þörungar&Pseudokirchnerella subcapitata\\
      2-Hýdroxýetýl metakrýlat (868-77-9)&EC50&380 mg/l&48 klst&Daphnia&Daphnia magna\\
      2-Hýdroxýetýl metakrýlat (868-77-9)&NOEC&160 mg/l&72 klst&Þörungar&Pseudokirchnerella subcapitata\\
      2-Hýdroxýetýl metakrýlat (868-77-9)&NOEC&24,1 mg/l&21 dagur&Daphnia&Pseudokirchnerella subcapitata\\
      Akrýlsýra (79-10-7)&LC50&27 mg/l&96 klst&Fiskur&Oncorhynchus mykiss\\
      Akrýlsýra (79-10-7)&NOEC&0,13 mg/l&21 dagur&Daphnia&Daphnia magna\\
      Akrýlsýra (79-10-7)&EC50&0,13 mg/l&72 klst&Þörungar&Desmodesmus subspicatus\\
      Maleic sýra (110-16-7)&LC50&> 245 mg/l&48 klst&Fiskur&Leuciscus idus\\
      Maleic sýra (110-16-7)&EC50&42,81 mg/l&48 klst&Daphnia&Daphnia magna\\
      Metakrýlsýra (79-41-4)&LC50&100 - 180 mg/l&96 klst&Fiskur&Danio rerio\\
      Metakrýlsýra (79-41-4)&EC50&> 8,2 mg/l&&Þörungar&\\
      Metakrýlsýra (79-41-4)&EC50&> 130 mg/l&48 klst&Daphnia&Daphnia magna\\
      Hýdroxýprópýl metakrýlat (27813-02-1)&LC50&493 mg/l&48 klst&Fiskur&Leuciscus idus melanotus\\
    \end{longtable}

\end{boxtype1}
\end{document}

less maximal minimal

  • Welcome! Code fragments are useful in explanations, but combining your fragments into a complete, minimal example of code people can copy-paste-compile would make it easier to understand your situation, enable people to reproduce the problem and encourage people to try out solutions and answer your question. Right now, people have to first work out how to produce compilable code by guessing what might be needed. That's tiresome and may not produce the problem you are seeing at all reliably. – cfr Aug 22 '15 at 0:03
  • But I'm guessing that the nesting of longtable environments has something to do with it since you are probably effectively putting what looks like a long table into a single row or cell of another one. That will mean LaTeX cannot break the page within the inner long table at all (because it can't break a row). Your console output should be useful here - you likely have lots of warnings about bad boxes, including under-full ones. – cfr Aug 22 '15 at 0:08
  • I tried to complete your code but can't compile without error. I fixed the first runaway argument error but now I get undefined control sequence errors. I've loaded all the obvious packages: tikz, mdframed, longtable, inputenc (utf8), fontenc (T1). But that doesn't do it. – cfr Aug 22 '15 at 0:17
  • Thank you for your info. I cut the code down into one section, section 12, and included my preamble in a single code-example. I know it's still not "simple" but it gives the problem quite clearly. I am going to continue in narrowing the problem down. There should however not be any nested long tables. That is, each long table should end before the next one begins... I think is is something to do with this mdframed - longtable mashup but I am really not sure. – Benedikt Omarsson Aug 22 '15 at 0:34
  • I've tried to create a minimal example - or, at least, a somewhat less maximal one. I've added this to your question. If you find it does not accurately reflect the problem, just roll back my edit. If it does, you might want to use it as the basis for yours as much of your current code is irrelevant to the problem you are asking about. There is a bit more explanation of what I've done in the question (e.g. why I've suddenly changed the colours in random ways etc.) – cfr Aug 22 '15 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.