LaTeX forum ⇒ Graphics, Figures & TablesDotfill in cases environment

Information and discussion about graphics, figures & tables in LaTeX documents.
DavidH
Posts: 8
Joined: Sun Feb 05, 2012 4:33 pm

Dotfill in cases environment

Postby DavidH » Fri Nov 17, 2023 8:52 pm

I'm trying to use \dotfill in a cases environment within an equation. Right now I have the solution below.

However, the length of the line after the bracket goes beyond the limiting margin, as \textwidth is specified within the \tabularx command. The line is extended corresponding to the length of the input specified by #1 plus the width of the bracket. Somehow I need to subtract this from \textwidth. Any suggestions?

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}

\setlength{\parindent}{0pt}

\makeatletter

\newenvironment{DotCases}[1]{%  
    {#1}
    \left\{%
    \tabcolsep \z@
    \def\arraystretch{1.2}% linespread: adjust as you please
    \tabularx{\textwidth}%
                {>{$}r<{$}>{${}}X<{$}}%
}{%
    \endtabularx
    \right.%
    \kern -\nulldelimiterspace
}

\makeatother

\begin{document}

$
\begin{DotCases}{f(x)=}
&x   \dotfill \text{too}\\
&1-x \dotfill \text{long}
\end{DotCases}
$\\

$
f(x) = 1-x \dotfill \text{right length}
$

\end{document}


Suggestions to other solutions are welcome, as long as the dotfill in the cases environment is exactly identical to dotfill outside the cases environment (like the bottom equation above).

Thanks =)
Last edited by DavidH on Mon Nov 20, 2023 4:25 pm, edited 2 times in total.

Recommended reading 2021:

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

Dotfill in cases environment

Postby rais » Mon Nov 20, 2023 12:35 am

You could use \settowidth to get the natural width of everything that's left of the tabularx environment. The tricky thing is the width of the opening brace, because the higher the brace becomes, the wider it will be. For compensation you now can use an optional argument, e.g., \begin{DotCases}[x\\x\\x]{...} for 3 lines.
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabularx}

\setlength{\parindent}{0pt}

\newlength\dcw

\newenvironment{DotCases}[2][a\\b]{%
    \setlength\tabcolsep{0pt}%
    \def\arraystretch{1.2}% linespread: adjust as you please
    \settowidth\dcw{\ensuremath{#2\left\{\vphantom{\array{c}#1\endarray}\right.}}%
    #2 \left\{%
    \tabularx{\dimexpr\linewidth-\dcw\relax}{>{$}X<{$}}%
}{%
    \endtabularx
    \right.%
}

\begin{document}

$
\begin{DotCases}{f(x)=}
x   \dotfill \text{too}\\
1-x \dotfill \text{long}
\end{DotCases}
$

$
f(x) = 1-x \dotfill \text{right length}
$

\end{document}

The \vphantom has no width of its own, but it will have the height of an array with #1 elements for the opening brace to `grow'.

KR
Rainer

DavidH
Posts: 8
Joined: Sun Feb 05, 2012 4:33 pm

Dotfill in cases environment

Postby DavidH » Mon Nov 20, 2023 4:24 pm

Thank you.

To follow up, does that mean, that if more than two lines within the brace are present, the second argument has to be imposed? E.g.

$
\begin{DotCases}[x\\x\\x]{f(x)=}
1    \dotfill \text{not}
x    \dotfill \text{too}\\
1-x \dotfill \text{long}
\end{DotCases}
$


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 7 guests