TransWikia.com

Align first line between two minipage

TeX - LaTeX Asked on October 4, 2021

I want to put my text on columns. On the first on, it will never be lot of things, like a date. On the second, it will be some text, and possibly multiple lines. I want to make the text on the left column always aligned with the first line to the second column. But I can’t achieved it, even when there is only one line on the right column, the left one is not always aligned.

I tried all combinations of the minipage alignment ([t], [c], [b]). But it changed nothing.

Here is an example:

documentclass{standalone}
usepackage[francais]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}

usepackage{ifthen}

newcommand{dateWidth}{4cm}
newcommand{textWidth}{12cm}

renewcommand{exp}[6]{

  begin{minipage}[c]{dateWidth}
    flushright
    footnotesize
    #1        % Date
  end{minipage}
  begin{minipage}[c]{textWidth}
    footnotesize

    ifthenelse{equal{#4}{}}{
      textbf{#2},
      textsl{#3}.
      {#6} %
    }{
      ifthenelse{equal{#6}{}}{
        textbf{#2},  % Titre du poste
        textsl{#3},  % Société
        {#4},   % Lieu
        {#5}.   % Contexte
      }{
        textbf{#2},  % Titre du poste
        textsl{#3},  % Société
        {#4},   % Lieu
        {#5}. % Contexte
        {#6}  % Description
      }
    }
  end{minipage}

}

begin{document}

  exp
    {2019 - 2020}
    {Lorem ipsum dolor}
    {sit amet}
    {consectetur adipiscing elit}
    {sed do eiusmod}
    {tempor incididunt ut labore et dolore magna aliqua. Commodo sed egestas
    egestas fringilla phasellus faucibus. In egestas erat imperdiet sed euismod.
    Mauris pellentesque pulvinar pellentesque habitant morbi tristique senectus
    et netus.}

  exp
    {2015 - 2018}
    {Faucibus ornare suspendisse}
    {sed nisi lacus}
    {Morbi enim nunc}
    {faucibus a pellentesque}
    {}

end{document}

In my real document, each exp are under each other. I didn’t achieved to do it in the example.

2 Answers

I understood that you need to align both the minipage should be top align, if yes:

documentclass{standalone}
usepackage[francais]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}

usepackage{ifthen}

newcommand{dateWidth}{4cm}
newcommand{textWidth}{12cm}

usepackage{adjustbox}

renewcommand{exp}[6]{
adjustbox{valign=t}{%
  begin{minipage}[c]{dateWidth}
    flushright
    footnotesize
    #1        % Date
  end{minipage}}
adjustbox{valign=t}{%
  begin{minipage}[c]{textWidth}
    footnotesize

    ifthenelse{equal{#4}{}}{
      textbf{#2},
      textsl{#3}.
      {#6} %
    }{
      ifthenelse{equal{#6}{}}{
        textbf{#2},  % Titre du poste
        textsl{#3},  % Société
        {#4},   % Lieu
        {#5}.   % Contexte
      }{
        textbf{#2},  % Titre du poste
        textsl{#3},  % Société
        {#4},   % Lieu
        {#5}. % Contexte
        {#6}  % Description
      }
    }
  end{minipage}
}
}

begin{document}

  exp
    {2019 - 2020}
    {Lorem ipsum dolor}
    {sit amet}
    {consectetur adipiscing elit}
    {sed do eiusmod}
    {tempor incididunt ut labore et dolore magna aliqua. Commodo sed egestas
    egestas fringilla phasellus faucibus. In egestas erat imperdiet sed euismod.
    Mauris pellentesque pulvinar pellentesque habitant morbi tristique senectus
    et netus.}

  exp
    {2015 - 2018}
    {Faucibus ornare suspendisse}
    {sed nisi lacus}
    {Morbi enim nunc}
    {faucibus a pellentesque}
    {}

end{document}

Excuse me, if my understand is wrong...

Answered by MadyYuvi on October 4, 2021

You want begin{minipage}[t] and not [c]. But there's no need to use a minipage with raggedleft for the date (note that flushright is wrong anyway).

Here's a “purified” version of your code, where the width of the second minipage is so it fills the whole remaining space.

documentclass{article}
usepackage[francais]{babel}
usepackage[utf8]{inputenc}
usepackage[T1]{fontenc}
usepackage[textwidth=18cm]{geometry}

usepackage{showframe}

usepackage{ifthen}

newcommand{dateWidth}{4cm}
newcommand{textWidth}{}
AtBeginDocument{edeftextWidth{thedimexprtextwidth-dateWidth-0.5emrelax}}

renewcommand{exp}[6]{%
  paraddvspace{topsep}noindent
  makebox[dateWidth][r]{footnotesize #1}hfill % Date
  begin{minipage}[t]{textWidth}
    footnotesize
    ifthenelse{equal{#4}{}}{%
      textbf{#2},
      textsl{#3}.ifthenelse{equal{#6}{}}{}{par#6}%
    }{%
      textbf{#2},  % Titre du poste
      textsl{#3},  % Société
      {#4},   % Lieu
      {#5}.% Contexte
      ifthenelse{equal{#6}{}}{}{par#6}% Description
    }%
  end{minipage}par
}

begin{document}

  exp
    {2019 - 2020}
    {Lorem ipsum dolor}
    {sit amet}
    {consectetur adipiscing elit}
    {sed do eiusmod}
    {tempor incididunt ut labore et dolore magna aliqua. Commodo sed egestas
    egestas fringilla phasellus faucibus. In egestas erat imperdiet sed euismod.
    Mauris pellentesque pulvinar pellentesque habitant morbi tristique senectus
    et netus.}

  exp
    {2015 - 2018}
    {Faucibus ornare suspendisse}
    {sed nisi lacus}
    {Morbi enim nunc}
    {faucibus a pellentesque}
    {}

end{document}

Beware of spurious spaces! The showframe package is only for making the text block more evident.

enter image description here

Answered by egreg on October 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP