LaTeX forum ⇒ Text FormattingHow to typeset double rule with text interrupting it? Topic is solved

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

How to typeset double rule with text interrupting it?

Postby user49915 » Sat Nov 16, 2019 7:24 pm

Let's assume we have the following junk to typeset (the right-hand side is not seen here):

TII3.png
Original
TII3.png (29.27 KiB) Viewed 5151 times


Here is what I tried so far:

\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:
file.png
My attempts
file.png (366.15 KiB) Viewed 5151 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 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook
rais
Posts: 345
Joined: Sun Nov 16, 2014 8:51 pm

How to typeset double rule with text interrupting it?

Postby rais » Sun Nov 17, 2019 5:03 pm

perhaps s.th. like this will do:
\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?

Postby user49915 » Mon Nov 18, 2019 5:35 pm

rais wrote:perhaps s.th. like this will do: [...]

Thank you. Your code gives me this:
mwe1.png
mwe1.png (364.5 KiB) Viewed 5078 times

In particular, the double line is unconnected to the rest of the table frame. Any idea of how to connect it?

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

How to typeset double rule with text interrupting it?

Postby rais » Mon Nov 18, 2019 10:44 pm

\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?

Postby user49915 » Tue Nov 19, 2019 1:28 pm

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: 4183
Joined: Thu Nov 01, 2012 4:08 pm

How to typeset double rule with text interrupting it?

Postby Johannes_B » Tue Nov 19, 2019 1:42 pm

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?

Postby user49915 » Tue Nov 19, 2019 2:01 pm

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

\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?

Postby user49915 » Tue Nov 19, 2019 3:29 pm

rais wrote:looks promising

Unfortunately, it breaks if you use the package tabularx (which is not uncommon in large monographs). The input
\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 5031 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 5015 times

Any help? (In the worst case, via \@ifpackageloaded.)

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

How to typeset double rule with text interrupting it?  Topic is solved

Postby rais » Wed Nov 20, 2019 1:34 am

well, if tabularx is needed, try
\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?

Postby user49915 » Wed Nov 20, 2019 3:51 pm

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 4961 times

The right overlap is similar.


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests