Text out of margin in latex multicols environment

environmentsmarginsxetex

I'm setting the margin configurations for multiple environments. For instances firstenvironment sets the margins using \setlength, then I make use of the multicols package inside the new environment. The problem is that the text doesn't seem to respect the bottom margin in the first page where the environment is just being used, but the text in the next pages do respect the margins. The same happens when I create a second environment with its own margin configurations. Not sure why the margins are not activated immediately when the environment begins. Any suggestions would be welcome, thanks!

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage{showframe} % show the frame margins
\usepackage{multicol}

\newenvironment{firstenvironment}{
    \setlength{\hoffset}{0mm}
    \setlength{\voffset}{0mm}
    \setlength{\headsep}{20pt}
    \setlength{\headheight}{4em}
    \setlength{\textheight}{6in}
    \setlength{\footskip}{10mm}}{}

\newenvironment{secondenvironment}{
    \setlength{\hoffset}{0mm}
    \setlength{\voffset}{0mm}
    \setlength{\headsep}{5pt}
    \setlength{\headheight}{2em}
    \setlength{\textheight}{5in}
    \setlength{\footskip}{20mm}}{}

\begin{document}
\begin{firstenvironment}
\setlength\columnsep{30pt}
\begin{multicols}{2}
        {\Large\bf 1ST LIPSUM}\\
        \lipsum[1-10]
    \end{multicols}
\end{firstenvironment}

\newpage

\begin{secondenvironment}
\begin{multicols}{2}
    {\Large\bf 2ND LIPSUM}\\
    \lipsum[1-10]
\end{multicols}
\end{secondenvironment}

\end{document}

enter image description here

Best Answer

I just figure out how to fix it. I made use of the package changepage. The idea is to include in the parameters of this command, the differences between the new margins and old margins. There is no need to use environments to set pages with different margins (which considers header, footer and margin notes), but to keep the same structure of the original post, I provide a solution that can be easily compared with.

\documentclass[12pt]{article}
\usepackage[paperheight=11in,paperwidth=8.5in,includeheadfoot]{geometry}
\usepackage{lipsum}
\usepackage{showframe} 
\usepackage{multicol}
\usepackage{changepage}
\usepackage{calc}

\newenvironment{firstenvironment}{}{}
\newenvironment{secondenvironment}{}{}

\begin{document}

\setlength{\textheight}{7in}
\setlength{\headsep}{20pt}
\setlength{\headheight}{4em}
\setlength{\footskip}{10mm}

\begin{firstenvironment}
    \begin{multicols}{2}
        {\Large 1ST LIPSUM}\\
        \lipsum[1-10]
    \end{multicols}
\end{firstenvironment}

\newpage
\changepage{-2in}{}{}{}{}{}{2em-4em}{5pt-20pt}{20mm-10mm}
%\changepage{textheight}{textwidth}{evensidemargin}{oddsidemargin}{columnsep}{topmargin}{headheight}{headsep}{footskip}

\begin{secondenvironment}
    \begin{multicols}{2}
        {\Large 2ND LIPSUM}\\
        \lipsum[1-10]
    \end{multicols}
\end{secondenvironment}

\restoregeometry

\begin{firstenvironment}
    \begin{multicols}{2}
        {\Large 3rd LIPSUM}\\
        \lipsum[1-10]
    \end{multicols}
\end{firstenvironment}

\end{document}
  • The command \changepage considers the following parameters: \changepage{textheight}{textwidth}{evensidemargin}{oddsidemargin}{columnsep}{topmargin}{headheight}{headsep}{footskip}
  • The margins that are left in blank under the \changepage command consider the default margins of the article class. If you want to restore the margins after setting a new one, just use the command \restoregeometry

enter image description here