5

In the following code, I have six functions typeset in three columns. I want the right parenthesis vertically aligned in each column and 2.5cm between the columns. (I use @{ } to put a single space between the right parenthesis and a function. It is typeset correctly in the first column.)

\documentclass{amsart}

\begin{document}

\begin{tabular}{r@{ }lp{2.5cm}r@{ }lp{2.5cm}r@{ }l}
i.)     &   $x^{2}$     &   ii.)    &      $x^{3}$  &   iii.)   &   $\sqrt{\vert x \vert}$ \\ [2ex]
iv.)    &   $\vert x \vert$ &   v.) &   $\sin{x}$   &   vi.)    &   $\ln{x}$
\end{tabular}

\end{document}

4 Answers 4

3

you have too many columns, if I got you question correctly the following should be enough:

\documentclass{amsart}

\begin{document}

\begin{tabular}{r@{ }p{2.5cm}r@{ }p{2.5cm}r@{ }l}
i.)     &   $x^{2}$     &   ii.)    &      $x^{3}$  &   iii.)   &   $\sqrt{x}$ \\ [2ex]
iv.)    &   $\vert x \vert$ &   v.) &   $\sin{x}$   &   vi.)    &   $\ln{x}$
\end{tabular}

\end{document}

enter image description here

10
  • Yes, that is what I wanted.
    – user74973
    Aug 23, 2016 at 19:35
  • I thought that r@{ }l put a space between the ) and function. I see that in your code, you kept the l only for the last column.
    – user74973
    Aug 23, 2016 at 19:37
  • yes, because in the last column you don't need space to the right, since it is the last. You can use p however.
    – d-cmst
    Aug 23, 2016 at 19:38
  • 1
    @user74973 the @{ } does put the space where you said. The problem with your code was that you then had a l for the function and the a p{2.5cm} which was the column for the ii.). You didn't need the l column
    – d-cmst
    Aug 23, 2016 at 19:43
  • 1
    l creates the last column, where the functions are aligned to left. p{2.5cm} also align the content to left, the difference is that with l the column takes the natural width of the content, while with p fixes the width of the column to a certain value (2.5cm) in this case
    – d-cmst
    Aug 23, 2016 at 19:50
3

You can use the tasks package instead:

\documentclass{amsart}

\usepackage{tasks}

\usepackage{lipsum} % just for the example

\settasks{
  before-skip=\bigskipamount,
  after-skip=\bigskipamount,
}

\begin{document}

\lipsum*[2]
\begin{tasks}[
  counter-format=tsk[r].),
  label-align=right,
  label-width=2em,
](3)
\task $x^{2}$
\task $x^{3}$
\task $\sqrt{\lvert x \rvert}$
\task $\lvert x \rvert$
\task $\sin{x}$
\task $\ln{x}$
\end{tasks}
\lipsum[3]

\end{document}

enter image description here

3

See, if the following is what you looking for:

\documentclass{amsart}
\begin{document}

{\renewcommand\arraystretch{1.5}
\begin{tabular}{rl@{\hspace{2.5cm}}rl@{\hspace{2.5cm}}rl}
i.)     &   $x^{2}$         &   ii.)    &      $x^{3}$  &   iii.)   &   $\sqrt{\vert x \vert}$ \\ 
iv.)    &   $\vert x \vert$ &   v.)     &   $\sin{x}$   &   vi.)    &   $\ln{x}$    
\end{tabular}
}
\end{document}

You have defined eight columns, so only first six was considered in table. To my taste is better to use l column type than p{...}.

enter image description here

enter image description here

Edit: second image is generated with code as you prefer to have. Now you can observe differences:

\documentclass{amsart}
\usepackage{array}

\begin{document}

{\renewcommand\arraystretch{1.5}
\begin{tabular}{r@{ }>{$}l<{$} @{\hspace{2.5cm}}r@{ }>{$}l<{$} @{\hspace{2.5cm}}r@{ }>{$}l<{$} }
i.)     &   x^{2}         &   ii.)    &      x^{3}  &   iii.)   &   \sqrt{\vert x \vert} \\ 
iv.)    &   \vert x \vert &   v.)     &   \sin{x}   &   vi.)    &   \ln{x}    
\end{tabular}
}
\end{document}

Note: Your question is not very clear, so the answer is based more or less on guessing and my taste. For typesetting of equations as you like to obtain with table people usually use specialized packages (task). As I already said, this again based on guessing.

Edit: Let me put attention to selection of column types. Using l (as I suggest) is intended for one line text and the width of columns are adopted to the widest cell. Contrary, p{...} type has fixed width (2.5 cm in your case) independent to cells content. If it is wider, then it is in normal circumstances broken into more lines (if the nature of contents allowed this). Contents in such cells is not left aligned (as at l) but justified (visible in multi-line contents).

I also slightly change the second MWE. In preamble I add package array and change columns l to >{$}l<{$}. With this is indicated, that contents in columns is math and you not need to put each cell into $ ... $.

4
  • I want to have one space between the ) and function. You had showed me to use r@{ }l. Why aren't you using that code here?
    – user74973
    Aug 23, 2016 at 19:40
  • why? to my taste your request lead to ugly result. if you persist to have @{} between r and l, than just insert it. it will eat space between those two columns, so I not recommended doing this.
    – Zarko
    Aug 23, 2016 at 19:51
  • No, I had typed r@{ }l and not r@{}l.
    – user74973
    Aug 23, 2016 at 19:56
  • sorry, I overlooked this. anyway, difference is negligible. i will added this your request to...
    – Zarko
    Aug 23, 2016 at 20:12
2

I corrected and simplified your code, but it has the drawback you have to type the labels by yourself. A more sensible solution is to use the tasks package, which is done for this sort of horizontal lists, or the shortlst package, which you'll have to install by yourself, as it's not part of TeX Live nor MiKTeX, for copyright reasons. Based on shortlst, I defined a tabenumerate environment, which does what you want. It uses two keys: nc, the number of columns (3 by default) and il, the interlinestretch.

Note that with tasks the first item is not well aligned, for some reason.

In the following code, all three solutions:

\documentclass{amsart}

\usepackage{tasks}
\usepackage{shortlst, xkeyval,  setspace}

\settasks{counter-format =tsk[r].), label-align=right,  label-offset=1em,before-skip =\smallskipamount, }


\makeatletter
\newcounter{ncol}
\define@key{lex}{nc}[3]{\setcounter{ncol}{#1}}%% 3 columns by default
\define@key{lex}{il}[1.5]{\def\@intln{#1}}% interlining![1]
\newenvironment{tabenumerate}[1][]{%
\setkeys{lex}{nc,il,#1}
\settowidth{\labelwidth}{\mbox{viii.)}}
\setlength{\leftmargini}{\dimexpr\labelwidth+\labelsep\relax}%[1][3]
\setlength{\shortitemwidth}{\dimexpr\linewidth/\value{ncol}-\labelwidth-2\labelsep\relax}%
\renewcommand{\labelenumi}{\roman{enumi}.)}
\setlength\labelsep{0.6em}
\setstretch{\@intln}
\begin{shortenumerate}}%
{\end{shortenumerate}
 }%

\begin{document}

\begin{tabular}{r@{ }l@{\hskip 2.5cm}r@{ }l@{\hskip 2.5cm}r@{ }l}
  i.)  & $x^{2}$           & ii.) & $x^{3}$   & iii.) & $√{\lvert x \rvert}$ \\ [2ex]
  iv.) & $\lvert x \rvert$ & v.)  & $\sin{x}$ & vi.)  & $\ln{x}$
\end{tabular}

\vspace{1cm}
\begin{tasks}(3)
  \task $x^{2}$
  \task $x^{3}$
  \task$√{\lvert x \rvert}$
  \task $\lvert x \rvert$
  \task $\sin{x}$
  \task $\ln{x}$
\end{tasks}

\vspace{1cm}
\begin{tabenumerate}[il=1.5]
  \item $x^{2}$
  \item $x^{3}$
  \item $√{\lvert x \rvert}$
  \item $\lvert x \rvert$
  \item $\sin{x}$
  \item $\ln{x}$
\end{tabenumerate}

\end{document} 

enter image description here

You must log in to answer this question.

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