5

I have an environment set up of longtables that I use as "tips"-boxes and exercises in my book. The left column shows only one word rotated (tips, exercise or whatever) while the right contains the rest of the text. Now the problem is that the right column is a single cell so (xe)latex decides to put the table on a new page if it is too big. Here is an example of what I mean: enter image description here

So how can I make it start on the current page and break whenever necessary, then continue on the next page?

My code for the table:

\documentclass[11pt]{book}

\usepackage{longtable}
\usepackage{array}
\usepackage{rotating}
\usepackage{lipsum}

\newcolumntype{M}[1]{>{%
  \parskip=0.5\baselineskip%
  \advance\parskip by 0pt plus 2pt
   \setlength{\parfillskip}{30pt plus 1fil}}m{#1}}

\newenvironment{exercise}[1]
{
    \begin{longtable}{m{0.05\textwidth}|M{0.85\textwidth}}
    \rotatebox{90}{\textbf{Övning}} & \textbf{#1} \newline
}
{\end{longtable}
\bigskip
}

\begin{document}

\lipsum

\begin{exercise}{1}
\lipsum
\end{exercise}

\end{document}
  • It is always best to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. – Peter Grill Oct 21 '11 at 18:49
  • Do you have to use a longtable or would you consider an answer involving mdframed? – cmhughes Oct 21 '11 at 18:54
  • @PeterGrill: updated with an MWE now, – pg-robban Oct 21 '11 at 19:02
  • @cmhughes: I never heard of mdframed, looking it up now. – pg-robban Oct 21 '11 at 19:02
6

You can't use longtable is such a combination. In the comment of cmhughes the package mdframed was recommended. In the example below you can find two possibilities with mdframed.

If you have further questions you can ask ;-)

EDIT: CHANGED CODE

\documentclass[11pt]{book}
\usepackage[framemethod=default]{mdframed}
\usepackage{rotating}

\usepackage{lipsum}
\makeatletter


\newrobustcmd\Titleenv[1]{%
   \setbox0=\hbox{\rotatebox[origin=cc]{90}{\textbf{#1}}}
   \setlength\@tempdimc{\dimexpr\ht0+\dp0\relax}
   \renewcommand*\md@@frametitle{%
      \llap{\smash{\raisebox{-.5\@tempdimc}{\box0}\hspace*{2em}}}}%
   \appto\md@frame@leftline@single{%
     \ifdimgreater{\mdfboundingboxheight}{\@tempdimc}%
     {}%
     {%
       \llap{\color{\mdf@middlelinecolor}%
           \rule[\dimexpr-.5\@tempdimc-\mdf@innerbottommargin@length\relax]%
                {\mdf@middlelinewidth@length}%
                {\dimexpr\@tempdimc+\mdf@innerbottommargin@length
                         +\mdf@innertopmargin@length\relax}%
            }%
     }%
   }%
}

\newenvironment{exercise}{%
  \mdfsetup{topline=false,rightline=false,bottomline=false,linecolor=red,
          linewidth=2pt,skipbelow=\topskip,skipabove=\topskip}
   \Titleenv{\"Ovning}%
\begin{mdframed}[]%
}{\end{mdframed}}

\begin{document}
\begin{exercise}
\lipsum[1]
\end{exercise}

\lipsum[1]

\begin{exercise}
Text
\end{exercise}

\lipsum[1]

\begin{exercise}
\lipsum
\end{exercise}
\end{document}

The code above results in the following picture: enter image description here

| improve this answer | |
  • it is better to call tlmgr --self --all update then the manager can update itself, too – user2478 Oct 22 '11 at 9:36
2

It is also possible to have the line and vertical text inside the default text width

\documentclass[11pt]{book}
\usepackage{framed}
\usepackage{rotating}
\usepackage{lipsum}   
\newenvironment{exercise}[1]
  {\par\begin{leftbar}\noindent\textbf{#1}\\
   \makebox(0,0){\put(-30,-50){\rotatebox{90}{\textbf{Övning}}}}\ignorespaces}
  {\end{leftbar}\par}

\begin{document}    
\lipsum

\begin{exercise}{1}
\lipsum
\end{exercise}

\end{document}

enter image description here

| improve this answer | |
  • I tried this option, and I had two problems: 1) I use lstlistings and it seems like the line numbers get in the way of the bar. 2): There seems to be spacing issues: i.imgur.com/FJxMI.png – pg-robban Oct 22 '11 at 11:32
  • give an example otherwise I cannot say what goes wrong – user2478 Oct 22 '11 at 12:48

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.