1

I am no expert in LaTeX. The table format for the below image was copied from here: https://tex.stackexchange.com/a/33761/206884

Unfortunately, when I apply this to my table definition the layout does no longer look good and the lines exceed the rows.

This is the code on my side. I have to embed it in the {table} as this is, what my writing program Scrivener gives to me.

\begin{table}[htbp]
\rowcolors{2}{tablerowcolor}{white}
\begin{minipage}{\linewidth}
\setlength{\tymax}{0.5\linewidth}
\centering
\small
\caption{Korrekte Definitionen - 1 Bit Liste}
\label{korrektedefinitionen-1bitliste-929}
\begin{tabulary}{\textwidth}{@{}L{0.30\textwidth}L{0.30\textwidth}L{0.2\textwidth}L{0.2\textwidth}@{}} \topline \headcol
 Häufige Funktionen & Realisierbar mit & Zustand bei ``1'' & Zustand bei ``0'' \\
\midline

 Licht, schaltende Verbraucher & Schaltaktor & Licht ein & Licht aus \\
 Status Rückmeldungen (allgemein) & Schaltaktor, Dimmaktor, Jalousieaktor & aktiv\slash ein\slash ja & nicht aktiv\slash aus\slash nein \\
\end{tabulary}
\end{minipage}
\end{table}

enter image description here

Does anybody have an idea how I can change that?

chris
  • 11
  • Hi Christian, please move the second question to a separate question. It is a bit difficult to help you with the first part as the definition of the coloring is probably given in the part of the document that you don't show here. Best is to create just the table in another Scrivener document and then post the complete exported document. – Uwe Ziegenhagen Feb 13 '20 at 16:50
  • Please extend your code snippet to complete small document, which we can test as it is. BTW, you have problem with @{} used in begin and end of column specifiers. Also column specifications are wrong – Zarko Feb 13 '20 at 18:05
  • @Uwe Deleted my 2nd question as this has been solved in the Scrivener forum. Zarko: Sveinung said something similar but the code compiles and the result looks good so it seems to work. I am really a newbie in Latex :-) – chris Feb 14 '20 at 07:16

2 Answers2

1

Simple versions of MWE with your tables:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{makecell, tabulary}

\begin{document}
    \begin{table}[htbp]
    \centering
    \small
\rowcolors{2}{white}{gray!10}
\begin{tabulary}{\textwidth}{@{}>{\columncolor{white}[0pt][\tabcolsep]}L LL
                                >{\columncolor{white}[\tabcolsep][0pt]}L @{}}
    \Xhline{0.8pt}%\topline \headco
 Häufige Funktionen & Realisierbar mit & Zustand bei ``1'' & Zustand bei ``0'' \\
    \Xhline{0.5pt}

 Licht, schaltende Verbraucher & Schaltaktor & Licht ein & Licht aus \\
 Status Rückmeldungen (allgemein) & Schaltaktor, Dimmaktor, Jalousieaktor & aktiv\slash ein\slash ja & nicht aktiv\slash aus\slash nein \\
    \Xhline{0.8pt}
\end{tabulary}
    \caption{Korrekte Definitionen - 1 Bit Liste}
\label{korrektedefinitionen-1bitliste-929}
    \end{table}
or 
    \begin{table}[htbp]
    \centering
    \small
\rowcolors{2}{white}{gray!10}
\begin{tabulary}{\textwidth}{*{4}{L}}
    \Xhline{0.8pt}%\topline \headco
 Häufige Funktionen & Realisierbar mit & Zustand bei ``1'' & Zustand bei ``0'' \\
    \Xhline{0.5pt}

 Licht, schaltende Verbraucher & Schaltaktor & Licht ein & Licht aus \\
 Status Rückmeldungen (allgemein) & Schaltaktor, Dimmaktor, Jalousieaktor & aktiv\slash ein\slash ja & nicht aktiv\slash aus\slash nein \\
    \Xhline{0.8pt}
\end{tabulary}
    \caption{Korrekte Definitionen - 1 Bit Liste}
\label{korrektedefinitionen-1bitliste-929}
    \end{table}
\end{document}

enter image description here

Zarko
  • 296,517
0

Your code snippet has wrong syntax for the use of tabulary. That package defines the column width relatively to the other columns. You do not use a fixed width.

The coloured side bearings sticking out on each side, you remove using a \kern{\tabcolsep} that you redirect into the first and last columns. Since tabulary use paragraph columns 8for multiple lines), you need to use a \leavevmode.

In other word, you place

 >{\leavevmode\kern-\tabcolsep}

on the left side of the column definition, and

<{\leavevmode\kern-\tabcolsep}

on the right side of the column definition (i.e. n the the table preamble).

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{tabulary, booktabs}

\begin{document}

\begin{table}[htbp]
\rowcolors{2}{lightgray}{white}
\setlength{\tymax}{0.5\linewidth}
\centering
\small
\caption{Korrekte Definitionen - 1 Bit Liste}
\label{korrektedefinitionen-1bitliste-929}
\begin{tabulary}{\textwidth}{>{\leavevmode\kern-\tabcolsep}LLLL<{\leavevmode\kern-\tabcolsep}}
\toprule
 Häufige Funktionen & Realisierbar mit & Zustand bei ``1'' & Zustand bei ``0'' \\
\midrule

 Licht, schaltende Verbraucher & Schaltaktor & Licht ein & Licht aus \\
 Status Rückmeldungen (allgemein) & Schaltaktor, Dimmaktor, Jalousieaktor & aktiv\slash ein\slash ja & nicht aktiv\slash aus\slash nein \\
\end{tabulary}
\end{table}

\end{document}
Sveinung
  • 20,355
  • That helped a lot. Thanks a lot. I could not copy your examples 1:1 but the trick for me that worked was replacing the @ with < and >. My solution: \begin{tabulary}{\textwidth}{>{}L{0.30\textwidth}L{0.30\textwidth}L{0.2\textwidth}L{0.2\textwidth}<{}} \topline \headcol – chris Feb 13 '20 at 19:32
  • @chris The tabulary you are using, is obviously not David Carlisle's version distributed as a LaTeX package. – Sveinung Feb 13 '20 at 23:30
  • I agree and that is what I meant with "could not copy 1:1". I always got errors and it would not compile with my code but the trick was to replace @ with < and >. That solved all my issues! – chris Feb 14 '20 at 07:14