2

I'm writing a book using Latex (obviously). Xetex actually. I'm doing a lot of tables w/ \parboxes in the table cells. In the end there's alot of repetitions and the code looks bad as a result (it's hard to find the content for the trees~). I faintly believe I've seen some suggestions in the direction of using some sort of list environment as well as custom (modular?) commands and lengths to refactor the code and do this leaner. Is that possible? How would that go?

I'd be so greatfull for the help.

My MWE, out of the book, goes like this

\documentclass{scrartcl}
\usepackage{fontspec} % for the Swedish chars
\usepackage{booktabs}
\begin{document}
\begin{table}[tb]
  \centering
  \begin{tabular}{@{}lll@{}}
    \toprule
    Lager & Vävnad & Syfte\\
    \midrule
    \parbox[t][][t]{.15\textwidth}{\raggedright\em
      Tunica intima
    } &
    \parbox[t][][t]{.25\textwidth}{\raggedright\em
      Tunt lager av endotelceller på insidan av ett lager av
      epitel- och bindvävsceller. 
    } &
    \parbox[t][][t]{.4\textwidth}{\raggedright\em
      Endotelet har flera viktiga funktioner.
    } \\

    \parbox[t][][t]{.15\textwidth}{\raggedright\em
      Tunica medica 
    } &
    \parbox[t][][t]{.25\textwidth}{\raggedright\em
      Smidig muskelvävnad och bindväv.
    } &
    \parbox[t][][t]{.4\textwidth}{\raggedright\em
      Genom att kontrahera musklerna minskar lumen och blodtrycket
      höjs.
    } \\

    \parbox[t][][t]{.15\textwidth}{\raggedright\em
      Tunica externa 
    } &
    \parbox[t][][t]{.25\textwidth}{\raggedright\em
      Yttre, skyddande bindvävslager.
    } &
    \parbox[t][][t]{.4\textwidth}{\raggedright\em
      Skyddar och håller kärlet i läge.
    } \\
    \bottomrule
  \end{tabular}  
  \caption[Kärlväggarnas tre lager]{De tre lagren som kärlväggarna
    består av.\label{tab:tunica}}
\end{table}
\end{document}

Cheers

4

LaTeX provides a p{length} specifier for this purpose. With array.sty, you can reduce the amount of repeated code by defining a new column specifier:

\documentclass{scrartcl}
\usepackage{fontspec} % for the Swedish chars
\usepackage{array,booktabs,ragged2e}

\newcolumntype{N}[1]{>{\hspace{0pt}\RaggedRight\itshape}p{#1\textwidth}}

\begin{document}
\begin{table}[tb]
  \centering
  \begin{tabular}{@{}N{.15}N{.25}N{.4}@{}}
    \toprule
    Lager & Vävnad & Syfte\\
    \midrule
    Tunica intima
          & Tunt lager av endotelceller på insidan av ett lager av
            epitel- och bindvävsceller. 
                   & Endotelet har flera viktiga funktioner. \\
    Tunica medica
          & Smidig muskelvävnad och bindväv.
                   & Genom att kontrahera musklerna minskar lumen och blodtrycket
                     höjs. \\
    Tunica externa 
          & Yttre, skyddande bindvävslager.
                   & Skyddar och håller kärlet i läge.\\
    \bottomrule
  \end{tabular}  
  \caption[Kärlväggarnas tre lager]{De tre lagren som kärlväggarna
    består av.\label{tab:tunica}}
\end{table}
\end{document}

enter image description here

  • Both great answers. Thanks. They're qualitative quite similar (I think) and since Arash is the least in reputation and first to answer, I hope I do the right thing by giving the green checkmark for the first answer. – Mats May 25 '16 at 20:02
2

I propose a solution with tabularx. I also added (automatically) some vertical padding between rows, with the cellspace package:

\documentclass[11pt]{scrartcl}
\usepackage{fontspec} % for the Swedish chars
\usepackage{polyglossia}
\setmainlanguage{swedish}
\usepackage{fontspec} % for the Swedish chars
\setmainfont{Minion Pro}

\usepackage{array,booktabs,ragged2e, tabularx}
\newcolumntype{L}{>{\RaggedRight\itshape\arraybackslash\hsize=.18\hsize}X}
\newcolumntype{M}{>{\RaggedRight\itshape\arraybackslash\hsize=.32\hsize}X}
\newcolumntype{R}{>{\RaggedRight\itshape\arraybackslash\hsize=.5\hsize}X}
\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\addparagraphcolumntypes{L, M, R}

 \begin{document}

\begin{table}[tb]
  \centering
  \begin{tabularx}{\linewidth}{@{}S{L}S{M}S{R}@{}}
    \toprule
    Lager & Vävnad & Syfte\\
    \midrule
    Tunica intima
          & Tunt lager av endotelceller på insidan av ett lager av
            epitel- och bindvävsceller.
                   & Endotelet har flera viktiga funktioner. \\
    Tunica medica
          & Smidig muskelvävnad och bindväv.
                   & Genom att kontrahera musklerna minskar lumen och blodtrycket
                     höjs. \\
    Tunica externa
          & Yttre, skyddande bindvävslager.
                   & Skyddar och håller kärlet i läge.\\
    \bottomrule
  \end{tabularx}
  \caption[Kärlväggarnas tre lager]{De tre lagren som kärlväggarna
    består av.\label{tab:tunica}}
\end{table}

\end{document} 

enter image description here

  • Both great answers. Thanks. They're qualitative quite similar (I think) and since Arash is the least in reputation and first to answer, I hope I do the right thing by giving the green checkmark for the first answer. – Mats May 25 '16 at 20:02
  • ...even though I, now, realize this might be a refinement of the previous answer. I was simply stuck figuring out which was the "best" answer. Anyway. Thanks again. – Mats May 25 '16 at 20:05
  • 1
    @Mats: That's fine with me. I don't post answers to win checkmarks, but to be helpful. The first answer is a very good answer – I just thought it could still be improved (to my taste…) using some other tools. – Bernard May 25 '16 at 20:32
  • Great, but it's tricky choosing the right one. You giys ARE so hlpfull abd that drive you share to be that is something to be careful of. Thanks for your improved suggestion. Be well. Cheers. – Mats May 25 '16 at 20:55

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.