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 a custom heading with dynamic content. My content is composed with tabulars, itemize and paragraphs. I am using the environment (samepage) with severals \nopagebreak in each part of the content to ensure that the content between two \nopagebreak will be on a new page or at least will stay together on two pages.

The content is correctly seperated. The problem is the header of the whole content doesn't follow the start of the content. The header stays in page 2 and the content starts at page 3. Here's the code that I use for the header.

\documentclass[12pt]{article}
\usepackage{lipsum}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{framed}
\usepackage[parfill]{parskip}
\definecolor{shadecolor}{RGB}{217,217,217}
\usepackage[left=0.75in,top=1.5in,right=0.75in,bottom=1in]{geometry}

\begin{document}
\lipsum[1]
\lipsum[2]
\lipsum[3]
\begin{samepage}
\nopagebreak
\begin{snugshade*}{\fontsize{13}{6}\selectfont\textbf{Testing}}\end{snugshade*}
\nopagebreak
\lipsum[4]
\nopagebreak
\lipsum[5]
\nopagebreak
\lipsum[6]
\end{samepage}

\end{document}

I saw that there's the minipage and needspace that I can use for undestructible blocks but the problem is that I have dynamic content so I do not know the lenght of it. I also try to put \nopagebreak after or before the header but it doesn't work.

My header and the dynamic content are inside one samepage block.

Any ideas how to fix this?

share|improve this question
1  
Please, explain what snugshade* is. –  egreg Sep 24 '12 at 19:56
    
snugshade makes a colored rectangle under the text. snugshade* is the same except that the left margin is aligned with the text below. The snugshade is aligned to the document margin. –  Pete Sep 24 '12 at 20:13
3  
What's the package providing it? Please add a minimal working example (MWE) that illustrates your problem. –  egreg Sep 24 '12 at 20:17
    
I have edited my 1st post to include some random text. –  Pete Sep 24 '12 at 20:34
    
I have put an answer that can replicate the snugshade* that would do the work I want. –  Pete Oct 1 '12 at 19:59

1 Answer 1

I have seen in the snugshade documentation (here) that it is using a colorbox with a defined color named shadecolor. When i use the colorbox in the code provided, the content are correctly seperated. So i have tried to recreate the snugshade with a tabular like this :

\colorbox{shadecolor}{
\begin{tabular}{@{}>{}p{\linewidth}@{}}
\fontsize{13}{6}\selectfont\textbf{Testing}
\end{tabular}}\\
share|improve this answer

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.