2

I would like to know how to right indent (for the first column only) while using tabbing. My code is

\documentclass{article}
\usepackage{enumitem}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{amsmath}
\usepackage{fancyhdr}
\usepackage{ragged2e}

\begin{document}

\begin{tabbing}
\hspace{1cm}\=\hspace{1cm}\=\kill
    300\>g\>Fleisch oder Fisch nach Wahl\\
    1\>EL\>Currypaste, rote\\
    200\>ml\>Wasser\\
    400\>ml\>Kokosmilch\\
    800\>g\>Gemüse nach Wahl\\
    2\>EL\>Fischsauce\\
    2\>EL\>Sojasauce, helle\\
    1\>EL\>Palmzucker oder brauner Rohrzucker\\
    2\>St.\>Peperoni, rot oder grün, schräg geschnitten\\
    2\>St.\>Chilischote(n), kleine scharfe (nach Belieben)\\
    6\>St.\>Thai-Basilikum Blätter\\
    2\>EL\>Rapskernöl oder Erdnussöl
\end{tabbing}
\end{document}

But the result should look like this. Right Indent by the First Column

  • 2
    Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – TobiBS Jul 23 at 16:30
  • ok sure. I just think that it will make my code messy. – Reynan Henry Jul 23 at 16:33
  • Well what you posted is not really a MWE, this is why it looks messy. ;-) Just keep it to the minimum, like I did in my answer and even there when you wouldn't use Umlauts, you could get rid of the inputenc. – TobiBS Jul 23 at 16:37
2

I suggest, that instead of the tabbing environment, you make use of tabular and then define the columns as rll. A complete example would be:

\documentclass{article}

\usepackage[utf8]{inputenc}

\begin{document}
\begin{tabular}{rll}
    300 & g & Fleisch oder Fisch nach Wahl\\
    1 & EL & Currypaste, rote\\
    200 & ml & Wasser\\
    400 & ml & Kokosmilch\\
    800 & g & Gemüse nach Wahl\\
    2 & EL & Fischsauce\\
    2 & EL & Sojasauce, helle\\
    1 & EL & Palmzucker oder brauner Rohrzucker\\
    2 & St. & Peperoni, rot oder grün, schräg geschnitten\\
    2 & St. & Chilischote(n), kleine scharfe (nach Belieben)\\
    6 & St. & Thai-Basilikum Blätter\\
    2 & EL & Rapskernöl oder Erdnussöl
\end{tabular}
\end{document}

It results in: enter image description here


Your additional question asks to keep the first two columns 1cm wide. This can be achieved with the help of the w column type provided by the array package:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{array} % for 'w' column type

\begin{document}
\begin{tabular}{@{}
                w{r}{1cm} % 1st col.
                @{\hspace{0.5\tabcolsep}} % only a small amount of sep.
                w{l}{1cm} % 2nd col.
                @{}
                l % 3rd and final col.
                @{}}
    300 & g  & Fleisch oder Fisch nach Wahl\\
      1 & EL & Currypaste, rote\\
    200 & ml & Wasser\\
    400 & ml & Kokosmilch\\
    800 & g  & Gemüse nach Wahl\\
      2 & EL & Fischsauce\\
      2 & EL & Sojasauce, helle\\
      1 & EL & Palmzucker oder brauner Rohrzucker\\
      2 & St.& Peperoni, rot oder grün, schräg geschnitten\\
      2 & St.& Chilischote(n), kleine scharfe (nach Belieben)\\
      6 & St.& Thai-Basilikum Blätter\\
      2 & EL & Rapskernöl oder Erdnussöl
\end{tabular}
\end{document}
| improve this answer | |
  • Hi, thanks for your help. If I may ask one more question: how can I make the first and second column 1cm in length? – Reynan Henry Jul 23 at 16:36
  • +1. You beat me to this tabular-based answer by a couple of minutes. :-) The only thing I'd change in your answer is to reduce the amount of whitespace between the first two columns by inserting, say, @{\hspace{0.5\tabcolsep}} between r and l (and, in the preamble, load the array package). – Mico Jul 23 at 16:38
  • @Mico do you want to go ahead and do that through an edit? I approve it! And I am happy that I am not the last to a party, at least once. It is sometimes really hard here on TeX.SE to be the first. :-) Especially on weekends at European night time, when there is a swarm of people that are helpful within minutes. ;-) – TobiBS Jul 23 at 16:47
  • @ReynanHenry If it is a new question, please accept this answer and open a new one. If it adds up to this one, please edit this question. – TobiBS Jul 23 at 16:54
  • @TobiBS - I've taken you up on your offer. Feel free to revert. :-) – Mico Jul 23 at 18:24
0

A tabular would be more flexible and versatile, but if you prefer to use tabbing, you can still achieve what you want using a \makebox[0pt][r]{..}.

\documentclass[12pt,a4paper]{article}
\begin{document}

\begin{tabbing}
\hspace{1cm}\=\hspace{1cm}\=\kill
  \makebox[0pt][r]{300}\>g\> Fleisch oder Fisch nach Wahl\\
  \makebox[0pt][r]{1}\>EL\> Currypaste, rote\\
  \makebox[0pt][r]{200}\>ml\> Wasser\\
  \makebox[0pt][r]{400}\>ml\> Kokosmilch\\
  \makebox[0pt][r]{800}\>g\> Gemüse nach Wahl\\
  \makebox[0pt][r]{2}\>EL\> Fischsauce\\
  \makebox[0pt][r]{2}\>EL\> Sojasauce, helle\\
  \makebox[0pt][r]{1}\>EL\> Palmzucker oder brauner Rohrzucker\\
  \makebox[0pt][r]{2}\>St.\> Peperoni, rot oder grün, schräg geschnitten\\
  \makebox[0pt][r]{2}\>St.\> Chilischote(n), kleine scharfe (nach Belieben)\\
  \makebox[0pt][r]{6}\>St.\> Thai-Basilikum Blätter\\
  \makebox[0pt][r]{2}\>EL\> Rapskernöl oder Erdnussöl
\end{tabbing}

\end{document}

enter image description here

| improve this answer | |

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.