-1

In the following TNWE (Tiny Not Working Example), I would like to align the braces on the right by calculating the lenghts of the texts such as to use \kern to fill spaces on right. Maybe blackmagic with boxes can do the job but this is far away from my tiny knowledge of LaTeX.

\documentclass[12pt]{article}

\newcommand\test[2]{
    \{#1\}
    
    \{#2\}
}

\parindent=0em

\begin{document}

\test{Hello}{the world...}

\end{document}

I would like to obtain :

{Hello       }
{the world...}

The macro will be used in some environments where I can't do whatever I want. This why I would like to use \kern.

1

No black magic, just standard features.

\documentclass[12pt]{article}

\newcommand{\dimmax}[2]{%
  \ifdim#1>#2 #1\else #2\fi
}
\newlength{\testupper}
\newlength{\testlower}
\newcommand\test[2]{%
  \par % ?
  \settowidth\testupper{#1}%
  \settowidth\testlower{#2}%
  \{\makebox[\dimmax{\testupper}{\testlower}][l]{#1}\}\par
  \{\makebox[\dimmax{\testupper}{\testlower}][l]{#2}\}\par
}

\setlength{parindent}{0pt}

\begin{document}

\test{Hello}{the world\dots}

\end{document}

enter image description here

| improve this answer | |
  • Thanks. For me this looks like a little of sorcery for the moment. :-) – projetmbc Jun 23 at 22:08
1

enter image description here



\documentclass[12pt]{article}

\newcommand\test[2]{%%
\par
\begin{tabular}{@{}l@{}l@{}l@{}}%
\{&#1&\}\\%
\{&#2&\}%
\end{tabular}\par}


\newcommand\testb[2]{%%
\par
\sbox0{#1}%
\sbox2{#2}%
\{#1\ifdim\wd2>\wd0 \kern\dimexpr\wd2-\wd0\relax\fi\}\par
\{#2\ifdim\wd0>\wd2 \kern\dimexpr\wd0-\wd2\relax\fi\}\par
}


\parindent=0em

\begin{document}

\test{Hello}{the world...}


\testb{Hello}{the world...}

\end{document}


| improve this answer | |
  • This works but I can't use this solution as I mention it at the end of my post. – projetmbc Jun 23 at 21:57
  • 1
    @projetmbc thought you might say that:-) I was adding a testb version but I don't like it as much:-) See update – David Carlisle Jun 23 at 22:00
  • Thanks a lot or this solution. – projetmbc Jun 23 at 22:09
  • @projetmbc oh disaster! you've given the tick to that other bloke, he'll be so happy. – David Carlisle Jun 23 at 22:15
  • 1
    @projetmbc but he didn't do what you asked and use a kern:-) (you could centre these by using c in the first or using a kern of 0.5\dimexpr... before and after #1 and #2 in the testb case – David Carlisle Jun 23 at 22:29

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.