1

I often use minipages aligned to the top using the package adjustbox and the code:

    \noindent\adjustbox{valign=t}{\begin{minipage}{0.5\linewidth}

    \end{minipage}}%
    \hfill
    \adjustbox{valign=t}{\begin{minipage}{0.5\linewidth}

    \end{minipage}}

I would like to create a command so I don't have to write that every time. I tried:

    \newcommand{\mini2}[4]{%
    \noindent\adjustbox{valign=t}{\begin{minipage}{#1\linewidth}
    #2
    \end{minipage}} 
    \hfill
    \adjustbox{valign=t}{\begin{minipage}{#2\linewidth}
    #4
    \end{minipage}}

I would like to write inside my document something like that

    \mini2{0.5}{0.5}{something}{something else}

to have two minipages vertically aligned to the top.

Problem: My \newcommand is not working, and I can't find why.

Thank you for your help.

  • 3
    You cannot have numbers in the macro names. So \newcommand{\mini2}{...} won't work regardless of what ... is. – user121799 Oct 27 '18 at 17:42
  • Tank you @marmot – Zanzi Oct 27 '18 at 18:11
  • Besides that you cannot have digits in multi-letter-command-names your command doesn't use the argument #3 at all. Seems to be a typo/seems #2 is also used in the place where #3 should be used. Also make sure to end lines where LaTeX due to \endlinechar might place an undesired space with comment-chars (%). – Ulrich Diez Oct 27 '18 at 19:14
1

Following you idea, try the following

\newcommand{\minii}[4]{%
    \noindent\adjustbox{valign=t}{\begin{minipage}{#1\linewidth}
    #3
    \end{minipage}} 
    \hfill
    \adjustbox{valign=t}{\begin{minipage}{#2\linewidth}
    #4
    \end{minipage}}

However, I guess that the following suggestion would be a clearer code

\def\beginmini#1{%
   \noindent
   \adjustbox{valighn=t}{%
   \begin{minipage}{#1\linewidth}
   }

\def\endmini{%
   \end{minipage}

And then you could simply

\beginmini{<your value>}
   <your text>
\endmini
%
\beginmini{<your other value>}
   <your other text>
\endmini

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.