1

I'm trying to create list of books with 3 columns and using new environment (I have to use environment here) to define my longtable. I want to get something like this :

enter image description here

But my code isn't working properly, it looks like below (also what's a "c" at the top?). What did I miss here ?
enter image description here

Here's my code :

\documentclass{article}
\usepackage{longtable}
\usepackage{siunitx} 
\usepackage[utf8]{inputenc}

\begin{document}
\newenvironment{books}{%
  \begin{longtable}{
        >{\raggedright}p{0.5cm}
        >{\raggedright}p{8.5cm}\\ 
        >{\raggedright}p{3.1cm} 
        }
  \end{longtable}
}

\newcommand\book[5]{%
 \textbf{#1} & \textbf{#2} & \textbf{#3} \\
             & \textsc{#4} &\\
             & #5 & \\}

\begin{books}
    \book
    {1.}{The Angel of Darkness by Caleb Carr.}{2019}
    {From 2 series of book.}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabiturdictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metusrhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapienest, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum}
    \book
    {2.}{The Alienist by Caleb Carr.}{2019}
    {From 2 series of book.}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabiturdictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metusrhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapienest, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum}
\end{books}
\end{document}
2
  • Your code results in error messages. In such a case, don't look at the output at all. Even if you get something that on first glance resembles a pdf file, there can still be issues with it. After an error, TeX only tries to recover enough to syntax check more of the file, it does not try to make sensible output after an error.
    – leandriis
    Feb 14, 2020 at 6:51
  • Could you please explain the connection to multicolumn` that you used in the title and the tags of your question? I can't see any hint on it in the code.
    – leandriis
    Feb 14, 2020 at 6:52

1 Answer 1

3

Three mistakes:

  1. Use \arraybackslash after \raggedright
  2. The linebreak \\ after second column specification seems superfluous
  3. \newenvironment has two parameters: one \begin{}, the other \end{}

Here's the modified code:

\documentclass{article}
\usepackage{longtable}
\usepackage{siunitx} 
\usepackage[utf8]{inputenc}

\begin{document}
\newenvironment{books}{%
  \begin{longtable}{
        >{\raggedright\arraybackslash}p{0.5cm}
        >{\raggedright\arraybackslash}p{8.5cm}  %%% \\ 
        >{\raggedright\arraybackslash}p{3.1cm} 
        }                        }{
  \end{longtable}
}

\newcommand\book[5]{%
 \textbf{#1} & \textbf{#2} & \textbf{#3} \\
             & \textsc{#4} &\\
             & #5 & \\}

\begin{books}
    \book
    {1.}{The Angel of Darkness by Caleb Carr.}{2019}
    {From 2 series of book.}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabiturdictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metusrhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapienest, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum}
    \book
    {2.}{The Alienist by Caleb Carr.}{2019}
    {From 2 series of book.}{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabiturdictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque.Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metusrhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapienest, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla,malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu,accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum}
\end{books}
\end{document}

with an output like this:

enter image description here

You must log in to answer this question.

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