Text FormattingHow to typeset double rule with text interrupting it?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to typeset double rule with text interrupting it?

Post by user49915 »

Let's assume we have the following junk to typeset (the right-hand side is not seen here):
Original
Original
TII3.png (29.27 KiB) Viewed 8812 times
Here is what I tried so far:

Code: Select all

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}%%% The main language is German
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{hhline}
\pagestyle{empty}
\begin{document}
\lipsum[1]\\

\noindent%
====\textsf{TII3}\leaders\hbox{=}\hfill\foreignlanguage{USenglish}{timed}====\strut\\
\begin{tabular}{@{}|p{\textwidth-1.35em}|@{}}
  %	\hhline{|=|}\\[-2.6ex]%%% Well, we need some text inside the double ruler.
  \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
    \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
    \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  \end{tabular}\\
  \hline\\[-2.2ex]
 \(\bar{z} = \bar{z'}\)\\
 \hline
\end{tabular}\\\\

\lipsum[2]
\end{document}
And here is the result:
My attempts
My attempts
file.png (366.15 KiB) Viewed 8812 times
1. Any idea how to typeset the header
╒═══TII3════...════timed═══╕

using a double ruler in the style of hhline, i.e., such that it attaches to the vertical lines of the table, and such that it doesn't look as if it were typed on a 1950's typewriter? Of course, one can use {xe|lua}latex and Unicode box drawings characters, but it would not work with pdflatex, and one would have to use a monospace alphabet and drop tabular anyway.

2. Any idea how to get rid of the ad-hoc width 1.35 em of the rulers and replace it by something automatically computed?

Thx in advance.
Last edited by user49915 on Mon Nov 18, 2019 2:51 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

How to typeset double rule with text interrupting it?

Post by rais »

perhaps s.th. like this will do:

Code: Select all

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}%%% The main language is German
\usepackage{lipsum}
\pagestyle{empty}

\newlength\drulesep% separation between the two lines of adouble rule
\newlength\druleshift% distance for lower rule of a double rule to baseline
\newlength\druleweight% thickness for each line of a double rule
\setlength\drulesep{0.5ex}
\setlength\druleshift{1pt}
\setlength\druleweight{0.4pt}
\newcommand*\drule[1]{% double rule
  \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
}
\newcommand*\drulefill{% double rule fill
  \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
}

\begin{document}
\lipsum[1]

\begin{center}
\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\\
\begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep}|}
  \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
    \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
    \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  \end{tabular}\\
  \hline\\[-2.2ex]
 \(\bar{z} = \bar{z'}\)\\
 \hline
\end{tabular}
\end{center}
 
\lipsum[2]
\end{document}
Going the hhline way, you'd still need to either push the text over the double rule or the double rules to the same vertical position as your text. Both sounded messy to me.

KR
Rainer
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to typeset double rule with text interrupting it?

Post by user49915 »

rais wrote:perhaps s.th. like this will do: [...]
Thank you. Your code gives me this:
mwe1.png
mwe1.png (364.5 KiB) Viewed 8739 times
In particular, the double line is unconnected to the rest of the table frame. Any idea of how to connect it?
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

How to typeset double rule with text interrupting it?

Post by rais »

Code: Select all

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}%%% The main language is German
\usepackage{lipsum}
\pagestyle{empty}

\newlength\drulesep% separation between the two lines of adouble rule
\newlength\druleshift% distance for lower rule of a double rule to baseline
\newlength\druleweight% thickness for each line of a double rule
\setlength\drulesep{0.5ex}
\setlength\druleshift{1pt}
\setlength\druleweight{0.4pt}
\newcommand*\drule[1]{% double rule
  \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
}
\newcommand*\drulefill{% double rule fill
  \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
}
\newcommand*\orule{%
  \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
}

\begin{document}
\lipsum[1]

\begin{center}
\orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule

\begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep-\arrayrulewidth}|}
  \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
    \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
    \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  \end{tabular}\\
  \hline\\[-2.2ex]
 \(\bar{z} = \bar{z'}\)\\
 \hline
\end{tabular}
\end{center}
 
\lipsum[2]
\end{document}
looks promising.
Not sure why my width calculation for the outer tabular was off, though.

The newly created \orule creates a vertical rule with the same thickness as the tabular's rules (\arrayrulewidth) and shifts everything that would protrude above the upper line of the double rule below the base line. What is shifted below the base line is hidden from LaTeX (the second [0pt] argument for the \raisebox command takes care of that), so that LaTeX won't leave any space between the \orule and the following line.
Of course, the two lines generated by those \orule commands should match those outer lines from the tabular; OTOH if you lower or widen the outer p{} specification, you can see how far those lines overlap ;-)

KR
Rainer
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to typeset double rule with text interrupting it?

Post by user49915 »

rais wrote: The newly created \orule creates a vertical rule with the same thickness as the tabular's rules (\arrayrulewidth) and shifts everything that would protrude above the upper line of the double rule below the base line. What is shifted below the base line is hidden from LaTeX (the second [0pt] argument for the \raisebox command takes care of that), so that LaTeX won't leave any space between the \orule and the following line.
Of course, the two lines generated by those \orule commands should match those outer lines from the tabular; OTOH if you lower or widen the outer p{} specification, you can see how far those lines overlap ;-)
If you omit centering and introduce \\ instead of a new para inside, you'll see overlapping, too. Artifacts start appearing only at magnification 2000%. One also does need \nopagebreak after the second \orule to keep the table on one page.
Last edited by user49915 on Tue Nov 19, 2019 2:47 pm, edited 2 times in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

How to typeset double rule with text interrupting it?

Post by Johannes_B »

Double backslash and noindent is certainly wrong. Dunno what you are doing, but it can't be a solution.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to typeset double rule with text interrupting it?

Post by user49915 »

Johannes_B wrote:Double backslash and noindent is certainly wrong. Dunno what you are doing, but it can't be a solution.
You are right. I meant

Code: Select all

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}%%% The main language is German
\usepackage{lipsum}
\pagestyle{empty}
\newlength\drulesep% separation between the two lines of a double rule
\newlength\druleshift% distance for lower rule of a double rule to baseline
\newlength\druleweight% thickness for each line of a double rule
\setlength\drulesep{0.5ex}
\setlength\druleshift{1pt}
\setlength\druleweight{0.4pt}
\newcommand*\drule[1]{% double rule
  \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
}
\newcommand*\drulefill{% double rule fill
  \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
}
\newcommand*\orule{%
  \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
}
\begin{document}
\lipsum[1]

\noindent%
\orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule\\%
\begin{tabular}{@{}|p{\dimexpr\textwidth-2\tabcolsep-\arrayrulewidth}|@{}}
  \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
    \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
    \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  \end{tabular}\\
  \hline\\[-2.2ex]
  \(\bar{z} = \bar{z'}\)\\
  \hline
\end{tabular}

\lipsum[2]
\end{document}
Here, the center environment is dropped, and you start seeing the overlapping.
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to typeset double rule with text interrupting it?

Post by user49915 »

rais wrote:looks promising
Unfortunately, it breaks if you use the package tabularx (which is not uncommon in large monographs). The input

Code: Select all

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}% warning: last language option will be chosen for fixed text of environments like example or definition (in svmono)
\usepackage{tabularx}
\newlength\drulesep% separation between the two lines of a double rule
\newlength\druleshift% distance for lower rule of a double rule to baseline
\newlength\druleweight% thickness for each line of a double rule
\setlength\drulesep{0.5ex}
\setlength\druleshift{1pt}
\setlength\druleweight{0.4pt}
\newcommand*\drule[1]{% double rule
  \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
}
\newcommand*\drulefill{% double rule fill
  \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
}
\newcommand*\orule{%
  \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
}
\pagestyle{empty}
\begin{document}
\begin{center}%
\orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule\nopagebreak
  
\begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep-\arrayrulewidth}|}
  \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
    \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
    \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  \end{tabular}\\
  \hline\\[-2.2ex]
  \(\bar{z} = \bar{z'}\)\\
  \hline
\end{tabular}%
\end{center}
\end{document}
produces
mwe.png
mwe.png (24.49 KiB) Viewed 8692 times
The right border is not a single line segment, but you see an overlapping of a line segment from above and a line segment from below:
screenshot.png
screenshot.png (1.85 KiB) Viewed 8676 times
Any help? (In the worst case, via \@ifpackageloaded.)
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

How to typeset double rule with text interrupting it?

Post by rais »

well, if tabularx is needed, try

Code: Select all

\documentclass{article}
\usepackage[USenglish,ngerman]{babel}%%% The main language is German
\usepackage{lipsum}
\usepackage{tabularx}
\usepackage{xcolor}
\pagestyle{empty}

\newlength\drulesep% separation between the two lines of adouble rule
\newlength\druleshift% distance for lower rule of a double rule to baseline
\newlength\druleweight% thickness for each line of a double rule
\setlength\drulesep{0.5ex}
\setlength\druleshift{1pt}
\setlength\druleweight{0.4pt}
\newcommand*\drule[1]{% double rule
  \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
}
\newcommand*\drulefill{% double rule fill
  \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
}
\newcommand*\orule{%
  \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
}

\begin{document}
\lipsum[1]

\begin{center}
{\color{cyan}\rule{\linewidth}{1pc}}% just for demo

\vspace{-\baselineskip}% just for demo
\orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule

\begin{tabular}{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}
  \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
    \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
    \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  \end{tabular}\\
  \hline\\[-2.2ex]
 \(\bar{z} = \bar{z'}\)\\
 \hline
\end{tabular}
\end{center}
 
\lipsum[2]
\end{document}
The stuff marked `just for demo' I just added to verify---or falsify---if the line with the double rules stays within text body's limits.

KR
Rainer
user49915
Posts: 81
Joined: Wed Apr 17, 2019 12:51 pm

How to typeset double rule with text interrupting it?

Post by user49915 »

rais wrote:well, if tabularx is needed, try
Thanks a lot, rais! You could add \nopagebreak right after the second \orule, but I think it's good enough now. For your information, that's how the left overlap looks like in large magnification in evince after compiling with pdflatex:
screenshot.png
screenshot.png (181 Bytes) Viewed 8622 times
The right overlap is similar.
Post Reply