Horizontal lines do not fit the table width *UPD!*

I an formatting a table at the moment and cannot figure out why the horizontal lines on the right of this table look out. You can see it better by commenting the "\renewcommands" of the preamble out.

Second point, commenting the geometry package out I get the output where the lines are shorter than the table width.

Why do my lines do not fit the line? How can I fix it? How the geometry package influence the table, if I do not use it here?

You will find the code below. Thank you!

\documentclass[12pt,ansinew,a4paper]{article}

\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage[german]{babel}
\usepackage{booktabs}
\usepackage{MnSymbol}

\newcolumntype{m}{>{$}c<{$}}

\renewcommand{\tabcolsep}{1.9ex}
\renewcommand{\arraystretch}{1.3}

\begin{document}
\rowcolors{1}{}{gray!15}
\begin{tabular*}{\textwidth}{|m|m|mmmmmm|}
\specialrule{0.08em}{0em}{0em}
A & B & \text{nicht} \ A & A \ \text{und} \ B & A \ \text{oder}\ B & A   \Rightarrow B & B \Rightarrow A & A \Leftrightarrow B\\
\specialrule{0.05em}{0em}{0em}
f & f & w & f & f & w & w & w\\
f & w & w & f & w & w & f & f\\
w & f & f & f & w & f & w & f\\
w & w & f & w & w & w & w & w\\
\specialrule{0.08em}{0em}{0em}
\end{tabular*}
\end{document}

• Welcome to the site! It's always a bonus for us if you strip your document down a bit so that it's minimal. There are a lot of custom commands and environments and unnecessary packages here that only serve to make your question a little bit harder to answer. If you get rid of them, it will make your question that bit more attractive and your answer will come that bit faster. – Au101 Oct 6 '16 at 19:35
• (I know it's a potential pain for you, but please try to make sure you don't remove packages from your preamble that are relevant, see this page for more advice: meta.tex.stackexchange.com/questions/228/…) It's like everything, the more you put in, the more you get out – Au101 Oct 6 '16 at 19:35
• Doing what Au101 suggested is also a good thing for you, as you notice things like that you load the array package twice ;) – hbaderts Oct 6 '16 at 19:46
• You also misspelled \displaystyle in \newcolumntype{D}{>{$\displaystile}X<{$}} which will surely bite you sooner or later – Au101 Oct 6 '16 at 19:47
• I ran your example and got this which looks OK, the \noindent at the start is wrong though, as is using [h] – David Carlisle Oct 6 '16 at 19:50

Discrepancy in line width and table width arise because you prescribe table width, but use columns which with is adopted to width of cells content which sum si smaller than text width.

Solution: instead of {tabular*}{\textwidth} use {tabularx}{\textwidth} and use suitability modified tabularx column type X. For example:

\documentclass[12pt,ansinew,a4paper]{article}
\usepackage{geometry}
\usepackage{amsmath}
\usepackage[table]{xcolor}
\usepackage{array,booktabs,tabularx}
\usepackage{caption}

\newcolumntype{m}{>{$}c<{$}}
\newcolumntype{C}{>{\centering \arraybackslash}X}
\renewcommand{\arraystretch}{1.3}

\begin{document}

\begin{table}[h]
\centering % <-- changed
\rowcolors{1}{}{gray!15}
\begin{tabularx}{\textwidth}{|>{$}C<{$}|>{$}C<{$}|*{6}{>{$}C<{$}}|}
\specialrule{0.08em}{0em}{0em}
A & B & \text{nicht} \ A & A \ \text{und} \ B & A \ \text{oder}\ B & A   \Rightarrow B & B \Rightarrow A & A \Leftrightarrow B\\
\hline%\specialrule{0.05em}{0em}{0em}
f & f & w & f & f & w & w & w\\
%\midrule
f & w & w & f & w & w & f & f\\
%\midrule
w & f & f & f & w & f & w & f\\
%\midrule
w & w & f & w & w & w & w & w\\
\hline%\specialrule{0.08em}{0em}{0em}
\end{tabularx}
\caption{Wahrheitstafel, $w$ = wahr $\land$ $f$ = falsch}
\end{table}
\end{document}


Edit: Usin tabularx table environment doesn't require that all columns had to be some sort of X type. You can use also columns type from tabular, however at least one had to be X type or based on it. For example if in above MWE you replace row with definition of columns with:

\begin{tabularx}{\textwidth}{|m|m|*{6}{>{$}C<{$}}|}


you will obtain more nice table (to my taste, of course):

• It works wonderful, thank you! Herewith: 1) Why there is {width} specificator in tabular*, if X does not work in this environment? I tried to do th whole width page in this environment but got an erroe message trying to use the X attribute there. 2) Is \centering work only in text mode, not in math mode? 3) Why did you use \centering in the middle of the code? Thank you! – Kirill Oct 6 '16 at 21:24
• @Kirill, good question ... but X column tape define tabularx package with function that it automatically calculate column width. Such facility tabular* hasn't. So with it you are on own to define column width. In some situation is handy to left to it calculation of tabcolsep with @{\extracolsep{\fill}}, i e. in your case \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|m|m|mmmmmm|} which unfortunately doesn't work well with colored rows. – Zarko Oct 6 '16 at 21:35
• True. That's why I used "specialrule(s)" for the table, also. Thank you very much! – Kirill Oct 6 '16 at 21:39
• @Kirill, see edit of my answer. use of specialrule hasn't any effect on column width, so I use ordinary \hline. And, if answer solve your problem, you can accept it ... :-) – Zarko Oct 6 '16 at 21:48
• I will definitly use it and accept it herewith! :) Or is there any function on the page that I can mark the answer as accepted? – Kirill Oct 6 '16 at 21:56