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: 62
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 377 times


Here is what I tried so far:

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage[USenglish,ngerman]{babel}%%% The main language is German
  3. \usepackage{tabularx}
  4. \usepackage{lipsum}
  5. \usepackage{calc}
  6. \usepackage{hhline}
  7. \pagestyle{empty}
  8. \begin{document}
  9. \lipsum[1]\\
  10.  
  11. \noindent%
  12. ====\textsf{TII3}\leaders\hbox{=}\hfill\foreignlanguage{USenglish}{timed}====\strut\\
  13. \begin{tabular}{@{}|p{\textwidth-1.35em}|@{}}
  14. % \hhline{|=|}\\[-2.6ex]%%% Well, we need some text inside the double ruler.
  15. \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
  16. \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
  17. \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  18. \end{tabular}\\
  19. \hline\\[-2.2ex]
  20. \(\bar{z} = \bar{z'}\)\\
  21. \hline
  22. \end{tabular}\\\\
  23.  
  24. \lipsum[2]
  25. \end{document}


And here is the result:
file.png
My attempts
file.png (366.15 KiB) Viewed 377 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.

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

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

perhaps s.th. like this will do:
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage[USenglish,ngerman]{babel}%%% The main language is German
  3. \usepackage{lipsum}
  4. \pagestyle{empty}
  5.  
  6. \newlength\drulesep% separation between the two lines of adouble rule
  7. \newlength\druleshift% distance for lower rule of a double rule to baseline
  8. \newlength\druleweight% thickness for each line of a double rule
  9. \setlength\drulesep{0.5ex}
  10. \setlength\druleshift{1pt}
  11. \setlength\druleweight{0.4pt}
  12. \newcommand*\drule[1]{% double rule
  13. \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  14. \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
  15. }
  16. \newcommand*\drulefill{% double rule fill
  17. \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
  18. }
  19.  
  20. \begin{document}
  21. \lipsum[1]
  22.  
  23. \begin{center}
  24. \drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\\
  25. \begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep}|}
  26. \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
  27. \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
  28. \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  29. \end{tabular}\\
  30. \hline\\[-2.2ex]
  31. \(\bar{z} = \bar{z'}\)\\
  32. \hline
  33. \end{tabular}
  34. \end{center}
  35.  
  36. \lipsum[2]
  37. \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: 62
Joined: Wed Apr 17, 2019 12:51 pm

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

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

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

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

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage[USenglish,ngerman]{babel}%%% The main language is German
  3. \usepackage{lipsum}
  4. \pagestyle{empty}
  5.  
  6. \newlength\drulesep% separation between the two lines of adouble rule
  7. \newlength\druleshift% distance for lower rule of a double rule to baseline
  8. \newlength\druleweight% thickness for each line of a double rule
  9. \setlength\drulesep{0.5ex}
  10. \setlength\druleshift{1pt}
  11. \setlength\druleweight{0.4pt}
  12. \newcommand*\drule[1]{% double rule
  13. \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  14. \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
  15. }
  16. \newcommand*\drulefill{% double rule fill
  17. \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
  18. }
  19. \newcommand*\orule{%
  20. \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
  21. }
  22.  
  23. \begin{document}
  24. \lipsum[1]
  25.  
  26. \begin{center}
  27. \orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule
  28.  
  29. \begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep-\arrayrulewidth}|}
  30. \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
  31. \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
  32. \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  33. \end{tabular}\\
  34. \hline\\[-2.2ex]
  35. \(\bar{z} = \bar{z'}\)\\
  36. \hline
  37. \end{tabular}
  38. \end{center}
  39.  
  40. \lipsum[2]
  41. \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: 62
Joined: Wed Apr 17, 2019 12:51 pm

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

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: 62
Joined: Wed Apr 17, 2019 12:51 pm

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

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage[USenglish,ngerman]{babel}%%% The main language is German
  3. \usepackage{lipsum}
  4. \pagestyle{empty}
  5. \newlength\drulesep% separation between the two lines of a double rule
  6. \newlength\druleshift% distance for lower rule of a double rule to baseline
  7. \newlength\druleweight% thickness for each line of a double rule
  8. \setlength\drulesep{0.5ex}
  9. \setlength\druleshift{1pt}
  10. \setlength\druleweight{0.4pt}
  11. \newcommand*\drule[1]{% double rule
  12. \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  13. \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
  14. }
  15. \newcommand*\drulefill{% double rule fill
  16. \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
  17. }
  18. \newcommand*\orule{%
  19. \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
  20. }
  21. \begin{document}
  22. \lipsum[1]
  23.  
  24. \noindent%
  25. \orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule\\%
  26. \begin{tabular}{@{}|p{\dimexpr\textwidth-2\tabcolsep-\arrayrulewidth}|@{}}
  27. \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
  28. \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
  29. \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  30. \end{tabular}\\
  31. \hline\\[-2.2ex]
  32. \(\bar{z} = \bar{z'}\)\\
  33. \hline
  34. \end{tabular}
  35.  
  36. \lipsum[2]
  37. \end{document}


Here, the center environment is dropped, and you start seeing the overlapping.

user49915
Posts: 62
Joined: Wed Apr 17, 2019 12:51 pm

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
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage[USenglish,ngerman]{babel}% warning: last language option will be chosen for fixed text of environments like example or definition (in svmono)
  3. \usepackage{tabularx}
  4. \newlength\drulesep% separation between the two lines of a double rule
  5. \newlength\druleshift% distance for lower rule of a double rule to baseline
  6. \newlength\druleweight% thickness for each line of a double rule
  7. \setlength\drulesep{0.5ex}
  8. \setlength\druleshift{1pt}
  9. \setlength\druleweight{0.4pt}
  10. \newcommand*\drule[1]{% double rule
  11. \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  12. \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
  13. }
  14. \newcommand*\drulefill{% double rule fill
  15. \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
  16. }
  17. \newcommand*\orule{%
  18. \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
  19. }
  20. \pagestyle{empty}
  21. \begin{document}
  22. \begin{center}%
  23. \orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule\nopagebreak
  24.  
  25. \begin{tabular}{|p{\dimexpr\textwidth-2\tabcolsep-\arrayrulewidth}|}
  26. \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
  27. \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
  28. \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  29. \end{tabular}\\
  30. \hline\\[-2.2ex]
  31. \(\bar{z} = \bar{z'}\)\\
  32. \hline
  33. \end{tabular}%
  34. \end{center}
  35. \end{document}

produces
mwe.png
mwe.png (24.49 KiB) Viewed 257 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 241 times

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

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

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

well, if tabularx is needed, try
Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage[USenglish,ngerman]{babel}%%% The main language is German
  3. \usepackage{lipsum}
  4. \usepackage{tabularx}
  5. \usepackage{xcolor}
  6. \pagestyle{empty}
  7.  
  8. \newlength\drulesep% separation between the two lines of adouble rule
  9. \newlength\druleshift% distance for lower rule of a double rule to baseline
  10. \newlength\druleweight% thickness for each line of a double rule
  11. \setlength\drulesep{0.5ex}
  12. \setlength\druleshift{1pt}
  13. \setlength\druleweight{0.4pt}
  14. \newcommand*\drule[1]{% double rule
  15. \makebox[0pt][l]{\raisebox{\dimexpr\druleshift+\druleweight+\drulesep}{\rule{#1}{\druleweight}}}%
  16. \raisebox{\druleshift}{\rule{#1}{\druleweight}}%
  17. }
  18. \newcommand*\drulefill{% double rule fill
  19. \leaders\hbox{\drule{0.1em}}\hfill\kern0pt%
  20. }
  21. \newcommand*\orule{%
  22. \raisebox{\dimexpr\druleshift+\drulesep+2\druleweight-\baselineskip}[0pt][0pt]{\rule{\arrayrulewidth}{\baselineskip}}%
  23. }
  24.  
  25. \begin{document}
  26. \lipsum[1]
  27.  
  28. \begin{center}
  29. {\color{cyan}\rule{\linewidth}{1pc}}% just for demo
  30.  
  31. \vspace{-\baselineskip}% just for demo
  32. \orule\drule{2em}\textsf{TII3}\drulefill\foreignlanguage{USenglish}{timed}\drule{2em}\strut\orule
  33.  
  34. \begin{tabular}{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}
  35. \begin{tabular}{@{}l@{\ \ }l@{}l@{\ }l@{}}
  36. \textsf{\textbf{in}} &\(z'\)&\(\colon\)&\textsf{T3}\\
  37. \textsf{\textbf{out}} &\(z\)&\(\colon\)&\textsf{T3}
  38. \end{tabular}\\
  39. \hline\\[-2.2ex]
  40. \(\bar{z} = \bar{z'}\)\\
  41. \hline
  42. \end{tabular}
  43. \end{center}
  44.  
  45. \lipsum[2]
  46. \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: 62
Joined: Wed Apr 17, 2019 12:51 pm

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

The right overlap is similar.


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests