4

I'm trying to create a a bipartite object that has the \textwidth at most, and doesn't overflow from the right, but has the width of the separator given as an argument.

I attempted to achieve this by scaling the left side with the first optional argument and then subtracting the same amount from the right. Problem is, this doesn't compile. The error message vaguely mentions that \relax is expecting a number, but I don't understand why doesn't it work.

\newcommand{\bipart}[3][0.06]
{
  \noindent
  \begin{minipage}[h]{#1\textwidth} %fine
    #2
  \end{minipage}
  \vrule \hspace{0.15in}
  \begin{minipage}[h]{(0.85-#1)\textwidth} %fails
    #3
  \end{minipage}
  \vspace{0.15in}
  \normalsize
}

A workaround would be to add another optional argument and always do the computation myself, however I don't like that, among other things, because I would need to renumber the arguments.

  • 1
    Welcome! Try \the\dimexpr0.85\textwidth-#1\textwidth instead of (0.85-#1)\textwidth. (I do however not see how a default value of 3 makes sense, 0.85-3 is very negative.) – user194703 Nov 6 '19 at 23:00
  • That compiled. The alignment is still wonky, but I think I can work my way from there. Why didn't the (0.85-#1) work? – Alex Petrosyan Nov 6 '19 at 23:06
  • 1
    Please always post a test document not a fragment, I assume (but you don't say) that you are using calc package. You are inserting word spaces in several places which you are not taking account of in the calculation , after the { after the \hspace after both of the end{minipage} – David Carlisle Nov 6 '19 at 23:10
  • 1
    minipage does not have a [h] option, the fact that it does not raise an error is just due to the memory limitations when that was implemented, it is just silently ignored – David Carlisle Nov 6 '19 at 23:12
  • 1
    @AlexPetrosyan Regarding your question "Why didn't the (0.85-#1) work?": When scanning a dimension, it looks for the sequence: optional signs, then either an internal dimen register (such as \textwidth) or <factor><unit of measure>, where <unit of measure> itself can be either a decimal constant (like 1 pt) or an internal dimen. Nowhere in this process TeX expects parenthesis or floating point calculations. The first one works because #1 is the <factor>. – Phelype Oleinik Nov 7 '19 at 11:50
2

“Naked” LaTeX doesn't understand (0.85-#1)\textwidth and you have to help it.

\documentclass[draft]{article}
\usepackage{xfp}

\usepackage{lipsum}% for context

\ExplSyntaxOn
\cs_new_eq:NN \dimeval \dim_eval:n
\ExplSyntaxOff

\newcommand{\bipart}[3][0.06]{%
  \par
  \addvspace{\topsep}
  \noindent
  \begin{minipage}{#1\textwidth} %fine
    #2
  \end{minipage}%
  \hspace{0.15in}%
  \vrule
  \hspace{0.15in}%
  \begin{minipage}{\dimeval{\fpeval{1-#1}\textwidth-0.3in-0.4pt}}
    #3
  \end{minipage}
  \par
  \addvspace{\topsep}
}

\begin{document}

\lipsum[1][1-3]
\bipart{a}{\lipsum[2][1-3]}
\lipsum[3]

\end{document}

I changed the algorithm: the vertical line has 0.15in to either side (your had a standard interword space on the left and 0.15in to the right).

The width of the other minipage is computed as “the complement to one of #1 times \textwidth minus 0.3in (the paddings) minus 0.4pt (the rule).

I also added vertical spaces at the top and bottom, rather than just the bottom.

enter image description here

| improve this answer | |

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.