Quantcast
Channel: Proper vertical spacing and pagebreaks in custom environment - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 4

Answer by John Kormylo for Proper vertical spacing and pagebreaks in custom environment

$
0
0

The heading is now actually part of the first line of text, so it cannot be separated.

\documentclass{article}\usepackage{xcolor}\usepackage{parskip}\newlength{\test}\newcommand\filltoend{\leavevmode\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}  \newcounter{example}  \newenvironment{example}[1][]{%  \refstepcounter{example}%  \vspace{0.5\baselineskip}\par\noindent%  \raisebox{\baselineskip}{\parbox[b]{\linewidth}%  {\textbf{Example~\theexample{}}~{\color{gray}\filltoend}% number and line  \settowidth{\test}{#1}\ifdim\test>0pt% test for optional argument  \vspace{0.5\baselineskip}\linebreak\textbf{#1}\fi}% Heading  \hspace{-\linewidth}}\hspace{\parindent}%start of text    }{%  \hfill% the following acts as a strut at the end of the line  {\hspace{-\linewidth}\color{gray}\rule[-.5\baselineskip]{\linewidth}{.4pt}}  \par}\begin{document}\rule{1pt}{.88\textheight}\\% Easier to adjustlast line.\begin{example}[My example]% adds a space if not commentedFusce mauris. Vestibulum luctus nibh at lectus. Sed bibendum, nulla a faucibussemper, leo velit ultricies tellus, ac venenatis arcu wisi vel nisl. Vestibulum diam.Aliquam pellentesque, augue quis sagittis posuere, turpis lacus congue quam,in hendrerit risus eros eget felis. Maecenas eget erat in sapien mattis porttitor.Vestibulum porttitor. Nulla facilisi. Sed a turpis eu lacus commodo facilisis.Morbi fringilla, wisi in dignissim interdum, justo lectus sagittis dui, et vehiculalibero dui cursus dui. Mauris tempor ligula sed lacus. Duis cursus enim utaugue. Cras ac magna. Cras nulla. Nulla egestas. Curabitur a leo. Quisqueegestas wisi eget nunc. Nam feugiat lacus vel est. Curabitur consectetuer.\end{example}New paragraph.\end{document}

To get the end of the environment to work I had to use actual text instead of \lipsum, which must include a \par at the end of each paragraph.


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images