1

I need to set the height of \vrule to the height of the actual text on the page, instead of to the full height of the text area. In the image below, the lines extend well beyond the text, but should stop at the bottom of the text.

Image showing over-extended lines

The lines were produced via the following code:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[a4paper,13pt]{memoir}
\usepackage{xparse}     
\usepackage{microtype}  
\usepackage{lettrine}   
\usepackage{eso-pic}    
\usepackage{multicol}   

\settypeblocksize{9.5in}{6.1in}{*}
\setlrmargins{*}{*}{0.85}
\checkandfixthelayout

\usepackage{fontspec,xltxtra,xunicode}
\setromanfont[Mapping=tex-text]{Phetsarath OT}  
\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Phetsarath OT}
\setmonofont[Scale=MatchLowercase]{Phetsarath OT}
\setlength{\headheight}{14pt}
\setlength{\parindent}{0em}


% set up ordinary footnotes
\makeatletter
\def\footnoterule{\kern-3\p@
  \hrule \@width \textwidth \kern 2.6\p@}
\makeatother
\renewcommand\thefootnote{\textit{\arabic{footnote}}}

% code to create chapters, verses, and cross references
\ExplSyntaxOn

\int_new:N \crossref_int
\int_new:N \vs_int
\tl_new:N \crossref_tl

% insert a cross reference
\NewDocumentCommand {\crossref} {m}
  {
    \int_compare:nNnT { \crossref_int } > { 25 }
      {
        \int_set:Nn \crossref_int { 0 }
      }
    \int_incr:N \crossref_int
% PROVIDES SUPERSCRIPTS FOR REFERENCES
%    \textsuperscript{ \emph { \int_to_alph:n { \crossref_int } } }
    \tl_if_empty:NF \crossref_tl
      {
        \tl_gput_right:Nn \emph { \crossref_tl { ~ } }
      }
    \tl_gput_right:Nx \crossref_tl
      {
% PROVIDES SUPERSCRIPTS FOR REFERENCES
%        \exp_not:N \textsuperscript
%          {
%            \exp_not:N \emph { \int_to_alph:n { \crossref_int } }
%          }
        \, #1
      }
  }

%Sample output
% insert chapter marker
\NewDocumentCommand {\ch} {m}
  {
    \int_gset:Nn \vs_int {1}
    \lettrine [findent=0.5em,nindent=0em] { #1 } {}
  }

% output cross references from previous verse and insert verse marker
\NewDocumentCommand {\vs} {m}
  {
    \tl_if_empty:NF \crossref_tl
      {
        \sidebar
          {
            \textbf { \int_use:N \vs_int } \, \tl_use:N \crossref_tl
          }
      }
    \int_gset:Nn \vs_int { #1 }
    \tl_gclear:N \crossref_tl
    %\textsuperscript { #1 \, }
    %\textbf { #1 \, }
    \par\textbf{\large{\textsuperscript{#1 \, }}}
  }

% output any remaining cross references
\AtEndDocument
  {
    \tl_if_empty:NF \crossref_tl
      {
        \sidebar
          {
            \textbf { \int_use:N \vs_int } \, \tl_use:N \crossref_tl
          }
      }
  }

\ExplSyntaxOff

% set up centre column location and size
\setlength\columnsep{2.2cm}     
\setlength{\sidebarhsep}{\dimexpr -0.5\textwidth - 0.5\columnsep + 2mm}
\setlength{\sidebarwidth}{\dimexpr \columnsep - 4mm}
\sidebarmargin{left}        
\renewcommand{\sidebarfont}{\footnotesize\normalfont}
\renewcommand*{\sidebarform}{\raggedright\hangindent 1mm}
\setlength{\sidebarvsep}{0ex}
\setsidebarheight{\dimexpr \textheight - 1ex}

% add vertical lines
\AddToShipoutPictureBG{%
  \AtTextUpperLeft{%
      \hskip \dimexpr 0.5\textwidth - 0.5\columnsep + 1mm
      \vrule depth \dimexpr \textheight - \ht\strutbox - 1pt
      \hskip \dimexpr\columnsep - 2mm
      \vrule depth \dimexpr \textheight - \ht\strutbox - 1pt}}

\begin{document}

\begin{multicols}{2}
  \ch{1}\crossref{John\ 1:1; [Col.\ 1:17; 1 John 1:1; Rev. 1:4, 8, 17; 3:14;
  21:6; 22:13]}In the beginning was \crossref{Rev.\ 19:13; [Heb.\ 4:12; 1 John
  1:1]}the Word, and \crossref{1 John 1:2; [ch.\ 17:5]}the Word was with God,
  and \crossref{Phil.\ 2:6}the Word was God. \vs{2}He was in the beginning
  with God. \vs{3}\crossref{ver.\ 10; Ps.\ 33:6; 1 Cor.\ 8:6; Col.\ 1:16;
  Heb.\ 1:2}All things were made through him, and without him was not any
  thing made that was made. \vs{4}\crossref{ch.\ 5:26; 11:25; 1 John 1:2;
  5:11}In him was life,\footnote{Or \emph{was not any thing made. That which
  has been made was life in him}} and \crossref{ch.\ 8:12; 9:5; 12:46}the life
  was the light of men.  \vs{5}\crossref{[ch.\ 3:19]}The light shines in the
  darkness, and the darkness has not overcome it.
\end{multicols}

[REST OF DOCUMENT TRUNCATED]

\end{document}

Some of the options I've looked at include attempting something with \settoheight{}, trying to use \strut somehow, or trying to do some height calculations with tikz before drawing the \vrule to suit. None of what I have attempted has helped, though I may not have been implementing it correctly.

Slightly complicating things, some pages may have a footnote with a horizontal rule above it. The vertical rule must not cross this, as the image below shows, but might meet it if the text stops within a certain margin of distance from the footnote.

Vertical rules crossing horizontal rule above footnote

Is there some way of specifying the actual height of text in similar fashion to \textheight? How could this be solved best?

6
  • please provide an example, your code fragment uses several commands not defined by default so I wouldn't be able to guess how to make a test file, also your image seems to show you are using some column balancing macros, as a standard two column always fills the first column, those macros will already have calculated the text height while balancing so that length can probably be used but the details are in code you have not shown. Jun 2 '21 at 14:25
  • @DavidCarlisle Thank you. I've added most of the preamble now and a piece of the document that follows. You may be right that something in that section is responsible. Perhaps I have been looking at the wrong place to find the troublespot.
    – Polyhat
    Jun 2 '21 at 14:38
  • Thanks. since you have now provided English text I think you can drop the font references as Phetsarath OT isn't in texlive and isn't actually needed for your cut down example. Jun 2 '21 at 14:52
  • in the new example the inserted middle column is longer than the main text, so presumably? you want the rules to be as long as the middle column in that case? Jun 2 '21 at 14:53
  • @DavidCarlisle The Lao text is part of what I didn't include. It follows the same markup style as the English, but few here would find it readable. The Lao is the actual language I'll be working with in the document, and the English was only for example purposes. There will likely be many places where a page is not entirely filled with text where the lines will need to be shortened to the actual text height.
    – Polyhat
    Jun 2 '21 at 15:00
2

It's probably easier to add the rules while you have the text in hand rather than later in a shipout hook.

This just modifies memoir's sidenote column to have rules

enter image description here

\documentclass[a4paper,13pt]{memoir}
\usepackage{xparse}     
\usepackage{microtype}  
\usepackage{lettrine}   
\usepackage{eso-pic}    
\usepackage{multicol}   

\makeatletter
\renewcommand{\sidecontents}{\hbox to \z@{%
  \m@mwhich@margin{\m@msidebar@margin}%
  \ifmemtortm
    \m@sideb@right
  \else
    \m@sideb@left
  \fi
    \@tempdima=\dimexpr\ht\sideins+\dp\sideins\relax
    \smash{\vrule depth \@tempdima}%
    \vtop to0pt{%
    \normalsize\normalfont\sidebarfont% select font so we know the strut size
    \vskip\topskip \vskip-\ht\strutbox
    \vskip\sidebartopsep% extra vertical shift
    \unvbox\sideins \vss}%
    \smash{\vrule depth \@tempdima}%
  \hss}%
}
\makeatother

\settypeblocksize{9.5in}{6.1in}{*}
\setlrmargins{*}{*}{0.85}
\checkandfixthelayout

\usepackage{fontspec} % don't use these in almost all cases ,xltxtra,xunicode}
%\setromanfont[Mapping=tex-text]{Phetsarath OT}  
%\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Phetsarath OT}
%\setmonofont[Scale=MatchLowercase]{Phetsarath OT}
\setlength{\headheight}{14pt}
\setlength{\parindent}{0em}


% set up ordinary footnotes
\makeatletter
\def\footnoterule{\kern-3\p@
  \hrule \@width \textwidth \kern 2.6\p@}
\makeatother
\renewcommand\thefootnote{\textit{\arabic{footnote}}}

% code to create chapters, verses, and cross references
\ExplSyntaxOn

\int_new:N \crossref_int
\int_new:N \vs_int
\tl_new:N \crossref_tl

% insert a cross reference
\NewDocumentCommand {\crossref} {m}
  {
    \int_compare:nNnT { \crossref_int } > { 25 }
      {
        \int_set:Nn \crossref_int { 0 }
      }
    \int_incr:N \crossref_int
% PROVIDES SUPERSCRIPTS FOR REFERENCES
%    \textsuperscript{ \emph { \int_to_alph:n { \crossref_int } } }
    \tl_if_empty:NF \crossref_tl
      {
        \tl_gput_right:Nn \emph { \crossref_tl { ~ } }
      }
    \tl_gput_right:Nx \crossref_tl
      {
% PROVIDES SUPERSCRIPTS FOR REFERENCES
%        \exp_not:N \textsuperscript
%          {
%            \exp_not:N \emph { \int_to_alph:n { \crossref_int } }
%          }
        \, #1
      }
  }

%Sample output
% insert chapter marker
\NewDocumentCommand {\ch} {m}
  {
    \int_gset:Nn \vs_int {1}
    \lettrine [findent=0.5em,nindent=0em] { #1 } {}
  }

% output cross references from previous verse and insert verse marker
\NewDocumentCommand {\vs} {m}
  {
    \tl_if_empty:NF \crossref_tl
      {
        \sidebar
          {
            \textbf { \int_use:N \vs_int } \, \tl_use:N \crossref_tl
          }
      }
    \int_gset:Nn \vs_int { #1 }
    \tl_gclear:N \crossref_tl
    %\textsuperscript { #1 \, }
    %\textbf { #1 \, }
    \par\textbf{\large{\textsuperscript{#1 \, }}}
  }

% output any remaining cross references
\AtEndDocument
  {
    \tl_if_empty:NF \crossref_tl
      {
        \sidebar
          {
            \textbf { \int_use:N \vs_int } \, \tl_use:N \crossref_tl
          }
      }
  }

\ExplSyntaxOff

% set up centre column location and size
\setlength\columnsep{2.2cm}     
\setlength{\sidebarhsep}{\dimexpr -0.5\textwidth - 0.5\columnsep + 2mm}
\setlength{\sidebarwidth}{\dimexpr \columnsep - 4mm}
\sidebarmargin{left}        
\renewcommand{\sidebarfont}{\footnotesize\normalfont}
\renewcommand*{\sidebarform}{\raggedright\hangindent 1mm}
\setlength{\sidebarvsep}{0ex}
\setsidebarheight{\dimexpr \textheight - 1ex}

% add vertical lines
\iffalse
\AddToShipoutPictureBG{%
  \AtTextUpperLeft{%
      \hskip \dimexpr 0.5\textwidth - 0.5\columnsep + 1mm
      \vrule depth \dimexpr \textheight - \ht\strutbox - 1pt
      \hskip \dimexpr\columnsep - 2mm
      \vrule depth \dimexpr \textheight - \ht\strutbox - 1pt}}
\fi
\begin{document}

\begin{multicols}{2}
  \ch{1}\crossref{John\ 1:1; [Col.\ 1:17; 1 John 1:1; Rev. 1:4, 8, 17; 3:14;
  21:6; 22:13]}In the beginning was \crossref{Rev.\ 19:13; [Heb.\ 4:12; 1 John
  1:1]}the Word, and \crossref{1 John 1:2; [ch.\ 17:5]}the Word was with God,
  and \crossref{Phil.\ 2:6}the Word was God. \vs{2}He was in the beginning
  with God. \vs{3}\crossref{ver.\ 10; Ps.\ 33:6; 1 Cor.\ 8:6; Col.\ 1:16;
  Heb.\ 1:2}All things were made through him, and without him was not any
  thing made that was made. \vs{4}\crossref{ch.\ 5:26; 11:25; 1 John 1:2;
  5:11}In him was life,\footnote{Or \emph{was not any thing made. That which
  has been made was life in him}} and \crossref{ch.\ 8:12; 9:5; 12:46}the life
  was the light of men.  \vs{5}\crossref{[ch.\ 3:19]}The light shines in the
  darkness, and the darkness has not overcome it.
\end{multicols}

[REST OF DOCUMENT TRUNCATED]

\end{document}

Or you could get multicols to add two rules between teh columns instead of one:

enter image description here

\documentclass[a4paper,13pt]{memoir}
\usepackage{xparse}     
\usepackage{microtype}  
\usepackage{lettrine}   
\usepackage{eso-pic}    
\usepackage{multicol}   

\makeatletter

% plan a
% \renewcommand{\sidecontents}{\hbox to \z@{%
%   \m@mwhich@margin{\m@msidebar@margin}%
%   \ifmemtortm
%     \m@sideb@right
%   \else
%     \m@sideb@left
%   \fi
%     \@tempdima=\dimexpr\ht\sideins+\dp\sideins\relax
%     \smash{\vrule depth \@tempdima}%
%     \vtop to0pt{%
%     \normalsize\normalfont\sidebarfont% select font so we know the strut size
%     \vskip\topskip \vskip-\ht\strutbox
%     \vskip\sidebartopsep% extra vertical shift
%     \unvbox\sideins \vss}%
%     \smash{\vrule depth \@tempdima}%
%   \hss}%
% }


% plan b make multicol add two rules
\setlength\columnseprule{1pt}
\def\LR@column@boxes{%
     \process@cols\mult@gfirstbox{%
       \ifdim\dp\count@>\dimen\tw@
         \global\dimen\tw@\dp\count@ \fi
       \mc@col@status@write
       \box\count@
       \kern2pt %
       {\columnseprulecolor\vrule\@width\columnseprule}%
       \hss
       {\columnseprulecolor\vrule \@width\columnseprule}%
       \kern2pt}%
     \ifdim\dp\mult@rightbox>\dimen\tw@
       \global\dimen\tw@\dp\mult@rightbox \fi
     \mc@lastcol@status@write
     \box\mult@rightbox
}
\LRmulticolcolumns

\makeatother

\settypeblocksize{9.5in}{6.1in}{*}
\setlrmargins{*}{*}{0.85}
\checkandfixthelayout

\usepackage{fontspec} % don't use these in almost all cases ,xltxtra,xunicode}
%\setromanfont[Mapping=tex-text]{Phetsarath OT}  
%\setsansfont[Scale=MatchLowercase,Mapping=tex-text]{Phetsarath OT}
%\setmonofont[Scale=MatchLowercase]{Phetsarath OT}
\setlength{\headheight}{14pt}
\setlength{\parindent}{0em}


% set up ordinary footnotes
\makeatletter
\def\footnoterule{\kern-3\p@
  \hrule \@width \textwidth \kern 2.6\p@}
\makeatother
\renewcommand\thefootnote{\textit{\arabic{footnote}}}

% code to create chapters, verses, and cross references
\ExplSyntaxOn

\int_new:N \crossref_int
\int_new:N \vs_int
\tl_new:N \crossref_tl

% insert a cross reference
\NewDocumentCommand {\crossref} {m}
  {
    \int_compare:nNnT { \crossref_int } > { 25 }
      {
        \int_set:Nn \crossref_int { 0 }
      }
    \int_incr:N \crossref_int
% PROVIDES SUPERSCRIPTS FOR REFERENCES
%    \textsuperscript{ \emph { \int_to_alph:n { \crossref_int } } }
    \tl_if_empty:NF \crossref_tl
      {
        \tl_gput_right:Nn \emph { \crossref_tl { ~ } }
      }
    \tl_gput_right:Nx \crossref_tl
      {
% PROVIDES SUPERSCRIPTS FOR REFERENCES
%        \exp_not:N \textsuperscript
%          {
%            \exp_not:N \emph { \int_to_alph:n { \crossref_int } }
%          }
        \, #1
      }
  }

%Sample output
% insert chapter marker
\NewDocumentCommand {\ch} {m}
  {
    \int_gset:Nn \vs_int {1}
    \lettrine [findent=0.5em,nindent=0em] { #1 } {}
  }

% output cross references from previous verse and insert verse marker
\NewDocumentCommand {\vs} {m}
  {
    \tl_if_empty:NF \crossref_tl
      {
        \sidebar
          {
            \textbf { \int_use:N \vs_int } \, \tl_use:N \crossref_tl
          }
      }
    \int_gset:Nn \vs_int { #1 }
    \tl_gclear:N \crossref_tl
    %\textsuperscript { #1 \, }
    %\textbf { #1 \, }
    \par\textbf{\large{\textsuperscript{#1 \, }}}
  }

% output any remaining cross references
\AtEndDocument
  {
    \tl_if_empty:NF \crossref_tl
      {
        \sidebar
          {
            \textbf { \int_use:N \vs_int } \, \tl_use:N \crossref_tl
          }
      }
  }

\ExplSyntaxOff

% set up centre column location and size
\setlength\columnsep{2.2cm}     
\setlength{\sidebarhsep}{\dimexpr -0.5\textwidth - 0.5\columnsep + 2mm}
\setlength{\sidebarwidth}{\dimexpr \columnsep - 4mm}
\sidebarmargin{left}        
\renewcommand{\sidebarfont}{\footnotesize\normalfont}
\renewcommand*{\sidebarform}{\raggedright\hangindent 1mm}
\setlength{\sidebarvsep}{0ex}
\setsidebarheight{\dimexpr \textheight - 1ex}

\begin{document}

\begin{multicols}{2}
  \ch{1}\crossref{John\ 1:1; [Col.\ 1:17; 1 John 1:1; Rev. 1:4, 8, 17; 3:14;
  21:6; 22:13]}In the beginning was \crossref{Rev.\ 19:13; [Heb.\ 4:12; 1 John
  1:1]}the Word, and \crossref{1 John 1:2; [ch.\ 17:5]}the Word was with God,
  and \crossref{Phil.\ 2:6}the Word was God. \vs{2}He was in the beginning
  with God. \vs{3}\crossref{ver.\ 10; Ps.\ 33:6; 1 Cor.\ 8:6; Col.\ 1:16;
  Heb.\ 1:2}All things were made through him, and without him was not any
  thing made that was made. \vs{4}\crossref{ch.\ 5:26; 11:25; 1 John 1:2;
  5:11}In him was life,\footnote{Or \emph{was not any thing made. That which
  has been made was life in him}} and \crossref{ch.\ 8:12; 9:5; 12:46}the life
  was the light of men.  \vs{5}\crossref{[ch.\ 3:19]}The light shines in the
  darkness, and the darkness has not overcome it.
\end{multicols}

[REST OF DOCUMENT TRUNCATED]

\end{document}
3
  • Thank you. That shows an interesting output that matches the length of the cross-references, but not the length of the text in the columns. I suppose it would be nice to have it match whichever is longest, but if only one or the other, the length of the text columns would be preferred.
    – Polyhat
    Jun 2 '21 at 15:23
  • @Polyhat it would be easy to arrange that multicol adds the two rules always, it already has code to add a single rule in the middle, you would just need to re-arrange it a bit to add two rules instead. I may post that later Jun 2 '21 at 15:59
  • @Polyhat added. with a bit of effort adjusting the kerns in the multicol version you could probably do both versions with the rules over-printing so you get the longest. Jun 2 '21 at 20:22

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.