0

I'd like to make a LaTeX environment for a styled box without using any additional packages, just defining some lines and spaces. I have already come far, but failing with the last line I imagined in this instance I realize that I don't have the correct impression of the underlying box model yet.

Target: A box with custom border lines, some padding and the possibility of any other LaTeX command inside. In this instance, I imagine a box with a thick line and a thin line along the left, while the thinner line joins the left tip of a short horizontal segment at the top, while the right side is like a 180° rotated copy of it, just without the thicker line.

In my class file I have already realized this as far as

\newenvironment{interrupt} {%
    \vspace{2em}%
    \noindent%
    \hspace{2.5pt}\rule{2em}{.2pt}\hspace{-2em}\hspace{-2.5pt}%
    \vline width .8pt%
    \hspace{1.5pt}%
    \vline width .2pt%
    \hspace{2em}%
    \begin{minipage}[t]{.9\linewidth}
    \vspace{1em}%
} {%
    \vspace{.5em}%
    \end{minipage}%
    %\vfill
    \hspace{2em}\vline width .2pt%
    \vfill%
    %\hspace{-2em}%
    \hfill%
    \rule{2em}{.2pt}%
    \vspace{2em}%
}

But the bottom right segment does not behave as I would expect it to and everything I tried about properly aligning it failed. So where am I thinking wrong?

If there's a good resource which explains this in detail and I just missed it, please link it!

Bonus question: OT, but related to the example, what is the best way to make the inner box dynamically use all available space minus the required padding?

Edit: minimal example of my specific case, as requested

\documentclass[a4paper]{article}

\makeatletter

\newenvironment{interrupt} {%
    \vspace{2em}%
    \noindent%
    \hspace{2.5pt}\rule{2em}{.2pt}\hspace{-2em}\hspace{-2.5pt}%
    \vline width .8pt%
    \hspace{1.5pt}%
    \vline width .2pt%
    \hspace{2em}%
    \begin{minipage}[t]{.9\linewidth}
    \vspace{1em}%
} {%
    \vspace{.5em}%
    \end{minipage}%
    %\vfill
    \hspace{2em}\vline width .2pt%
    %\vfill%
    %\hspace{-2em}%
    %\hfill%
    \rule{2em}{.2pt}%
    \vspace{2em}%
}

\makeatother


\begin{document}

Bla, bla blabla bla, bla.\\
Ba di da bla

\begin{interrupt} % the session and discussion is interrupted
    % and may be continued in the same context later
    How nice, a custom sample text.

    \begin{tabular}{c | c c}
        1   & 2 & 3\\\hline
        4   & 5 & 6\\
        7   & 8 & 9
    \end{tabular}
\end{interrupt}

Back to same bla\dots

\end{document}

right horizontal segment should atach to lower end, pointing left

  • Just to understand, with the \vfill, you want it to fill up all available space on the page? – Steven B. Segletes Jul 24 '18 at 16:16
  • What's your target TeX format? LaTeX or plain TeX? It seems that you want to use LaTeX… – TeXnician Jul 24 '18 at 16:17
  • @StevenB.Segletes the last \vfill is supposed to push the horizontal segment down to the bottom, without it was (at least) only at the very top of the vertical line – Peter Nerlich Jul 24 '18 at 17:23
  • @TeXnician LaTeX, but I am interested in explicitly plain TeX ways as well. I didn't find much explaining what I wanted using LaTeX on the internet and almost nothing for TeX, and if, just answers here that are specific to one question most of the time. – Peter Nerlich Jul 24 '18 at 17:27
  • Well, then I would question why you start with environments at all, because plain TeX doesn't know them. You should also rewrite the \vspace commands into TeX syntax (\vskip) etc. If you want to learn more TeX commands look at "TeX by Topic". – TeXnician Jul 24 '18 at 17:31
1

enter image description here

\documentclass[a4paper]{article}

\makeatletter

\newenvironment{interrupt} {%
    \par
    \addvspace{2em}%
    \noindent\hspace{2.5pt}\rule{2em}{.2pt}\hspace{\dimexpr-2.5pt-2em}%
    \vline width .8pt %
    \hspace{1.5pt}%
    \vline width .2pt %
    \hspace{2em}%
    \begin{minipage}[t]{\dimexpr\linewidth-5pt-4em}
    \vspace{1em}%
} {%
    \vspace{.5em}%
    \end{minipage}%
    \hspace{2em}%
    \vline width .2pt %
    \par
    \parskip0pt
    \nointerlineskip
    \noindent\hfill\rule{2em}{.2pt}\hspace*{2.5pt}%
    \par
    \addvspace{2em}%
}

\makeatother


\begin{document}

Bla, bla blabla bla, bla.\\
Ba di da bla

\begin{interrupt} % the session and discussion is interrupted
    % and may be continued in the same context later
    How nice, a custom sample text.

    \begin{tabular}{c | c c}
        1   & 2 & 3\\\hline
        4   & 5 & 6\\
        7   & 8 & 9
    \end{tabular}
\end{interrupt}

Back to same bla\dots

\end{document}
  • Well, it does solve my specific case and gives me some commands to look up. Can you also maybe explain where my expectation of how the boxes work was wrong? (Though I assume I have not have given enough information to make it a short answer) – Peter Nerlich Jul 24 '18 at 19:44
  • 1
    you were nearly there, main thing you were missing was a \par after the minipage to get below it so the bottom horizontal rule is at the bottom. @PeterNerlich – David Carlisle Jul 24 '18 at 19: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.