0

I'm trying to use \dotfill in a cases environment within an equation. I've adopted the solution here: Alignment and dotfill in cases

However, I'd like to be able to write something to the left of the bracket, without the dots going further than textwidth. Here is what I have

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

\makeatletter

\newcommand*\Annadotfill{%
    \leavevmode
    % Do you really want "\cleaders"?
    \cleaders \hb@xt@ .33em{\hss .\hss }\hfill
    \kern \z@
}
\@ifdefinable\@Anna@brace@width{\newdimen\@Anna@brace@width}
\settowidth\@Anna@brace@width{%
    $\left\{\vbox{\vskip \@m \p@}\right.\kern -\nulldelimiterspace$%
}
\newenvironment{Annacases}{%
    \left\{%
    \tabcolsep \z@
    \def\arraystretch{1.2}% linespread: adjust as you please
    \tabularx{\dimexpr \linewidth-\@Anna@brace@width \relax}%
                {>{$}r<{$}>{${}}X<{$}}%
}{%
    \endtabularx
    \right.%
    \kern -\nulldelimiterspace
}

\makeatother

\begin{document}

$
f(x) = \begin{Annacases}
x & \Annadotfill \text{text;}\\
1-x & \Annadotfill \text{more text;}
\end{Annacases}
$

\lipsum[1]

\end{document}

How can I modify the code to keep everything within textwidth?

1 Answer 1

2

enter image description here

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


\begin{document}

$
f(x) = 
\left\{
\begin{array}{@{}r@{}}
x\\
1-x
\end{array}
\right.
\leaders
\hbox{$%
\begin{array}{@{\,}r@{\,}}
.\\
.
\end{array}%
$}\hfill
\begin{tabular}{@{}r@{}}
  text;\\
more text;
\end{tabular}
$

\lipsum[1]

\end{document}
5
  • Thank you for the solution! However, I am writing a lot (hundreds) of these equations and with your suggestion the code will become very messy. Therefore I am looking for something a bit simpler. Is it possible to wrap your solution into a new environment/function?
    – DavidH
    Jun 21 at 10:42
  • 1
    @DavidH f(x)=\foo{x\\1-x}{.\\.}{text\\more text} with \newcommand\foo[3]{\left\{\begin{array}{@{}r@{}}#1\end{array}\right.\leaders\hbox{$\begin{array}{@{\,}r@{\,}}#2\end{array}$}\hfill\begin{tabular}{@{}r@{}}#3\end{tabular}} Jun 21 at 11:38
  • Thanks. This, however, does not have the same spacing between the dots as \dotfill. And I will be using a mix of the original function and the alternative.
    – DavidH
    Jun 22 at 17:40
  • 1
    @DavidH replace@{\,}r@{\,} for the dots with @{\hpace{.22em}}c@{\hpace{.22em}} as \dotfill uses \cleaders \hb@xt@ .44em{ Jun 22 at 19:46
  • Charlise Thanks for your solution. However, I am still looking for a slightly different approach. Based on previous solution linked to in the question, I have the following environment: \newenvironment{DotCases}[1]{{#1}\left\{\tabularx{\linewidth}{>{$}r<{$}>{${}}X<{$}}}{\endtabularx \right. \kern -\nulldelimiterspace} But I need to subtract the length of {#1} and \left\{ from \linewidth. Do you know how to do that?
    – DavidH
    Jun 25 at 9:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .