Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following code:

\documentclass{article}
\usepackage[cp1252]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{environ}
\usepackage{tabularx,array,booktabs}

\NewEnviron{woche}[2]{
 \paragraph*{Woche vom #1 bis #2}~\nopagebreak
 \vspace{1em}\\*
 \tabularx{0.97\textwidth}{m{0.9cm}X}
 \toprule
  \BODY
 \bottomrule
}[
 \endtabularx]

\begin{document}
\vspace*{16cm}
\begin{woche}{2}{3}
  28.11. & Was ich alles an dem ersten Tag dieser Woche getan habe! \\
  29.11. & Der zweite Tag wa recht lang. \\
  30.11. & Nur Doku geschrieben \\
  01.12. & Ich freie mich schon auf's Wochenende, aber noch sind wir nicht soweit. Ich muss noch ganze zwei Tage runterreißen. \\
  02.12. & Letzter Tag! Endlich! \\
\end{woche}
\end{document}

Now if I compile the file using pdfLaTeX I get two pages. On the first there is the heading Woche 2 bis 3 and on the second there is the table. The vspace is just to simulate some other text or things. How can I modify the environment to get it running?

share|improve this question
2  
Put a \par after the \endtabularx command. (It looks as if the grouping introduced by your environment confuses the page breaking). –  Ulrike Fischer Feb 13 '12 at 16:30
add comment

3 Answers

up vote 3 down vote accepted

The usual setting for \paragraph is that it typesets an inline heading. Change it as to be like \section, for example with the titlesec package:

\usepackage{titlesec}
\titleformat{\paragraph}{}{}{0pt}{\bfseries}
\titlespacing*{\paragraph}{0pt}{\baselineskip}{1.5ex}
\usepackage{environ}
\usepackage{tabularx,array,booktabs}

\NewEnviron{woche}[2]{%
 \paragraph*{Woche vom #1 bis #2}
 \tabularx{\textwidth}{m{0.9cm}X}
 \toprule
  \BODY
 \bottomrule
}[\endtabularx\par]

Adjust the spacing to suit your needs.

Alternatively, put the heading inside the tabularx and forget about \paragraph:

\NewEnviron{woche}[2]{%
 \par\addvspace{2.5ex}
 \noindent\tabularx{\textwidth}{m{0.9cm}X}
 \multicolumn{2}{@{}l@{}}{\bfseries Woche vom #1 bis #2}\\[1.5ex]
 \toprule
  \BODY
 \bottomrule}
 [\endtabularx\par]

This seems to be the cleanest solution.

share|improve this answer
add comment

Do you always want a line break after the heading? After a display heading LaTex goes to some trouble to prevent a page break, and will, as you wish, pull the entire heading on to the next page, you get that effect if you changed your code to say

 \section*{Woche vom #1 bis #2}

 \tabularx{0.97\textwidth}{m{0.9cm}X}

Instead of using paragraph*.

So simplest is to define \paragraph* to be a display heading rather than run-in. If you want most paragraphs to have a run-in heading unless the next thing is a big item like a table, then @ulrike-fischer's comment (which I just noticed) is probably your answer.

share|improve this answer
    
I don't know if my comment is really the answer. In this case it works (and it was quite interesting to see that the grouping has this effect) but TeX can be quite stubborn and insert a page break at ` \\ ` regardless of \nobreaks or \nopagebreaks or * used to prevent it. So I think your and Enrico's suggestion to use a real display heading command is the real answer. –  Ulrike Fischer Feb 14 '12 at 8:54
add comment

The \vspace*{16cm} is forcing the table to the next page. Test it with 1cm and then adjust to taste!

share|improve this answer
1  
I want BOTH the heading and the table on the second page. It's because there are severat such environments after each other and one of those environments gets "broken". The vspace just simulates the other things on the first page. –  Christian Wolf Feb 13 '12 at 17:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.