# Table format issues. Column lines and horizontal lines are not with proper margins + caption alignment

Table format issues. Column lines and horizontal lines are not with proper margins. Caption alignment is also not proper if change in minipage width setting

%%%%%%%%%%%%%%%%

\begin{table}

\centering

\begin{minipage}{.5\textwidth}

\begin{tabular}{|c|c|c|c|}

\hline

\textbf{Id} & \textbf{Age} & \textbf{Lab-tests} & \textbf{Time-in-Hospital} \\ \hline

1  & 45 & 13 & 35 \\ \hline

2  & 35 & 7 & 20 \\ \hline

3  & 30 & 5 & 25 \\ \hline

4  & 55 & 10 & 28 \\ \hline

5 & 40 & 14 & 38 \\ \hline

\end{tabular}

\caption{\label{tab:ptabular} Patients}

\end{minipage}

\end{table}

%%%%%


Output:

If I put in minipage:

\begin{minipage}{\textwidth}


I get the following output:

Now, I could not understand why the caption is not center aligned. Why are columns not appearing and horizontal lines are extended?

I would like to mention that I am not using \documentclass{article} (if use it, it works perfectly), but a specific documentclass of paper that is, \documentclass{kais}. KAIS style file is available here. http://www.ucs.louisiana.edu/~xxw8007/kais/LaTeX/

• Welcome to TeX SX! I've tested with the kais.cls and have no problem. Could you post a full compilable code that reproduces the problem? – Bernard Jul 11 '18 at 15:17
• Why are you using a minipage to enclose the tabular environment? – leandriis Jul 11 '18 at 17:38
• If you put an \fbox around the minipage, you will see that the tabular doesn't fit. OTOH, my result didn't look anything like yours, probably due to unknown packages or all those blank lines. – John Kormylo Jul 11 '18 at 22:45
• @JohnKormylo I create a sample. Result still the same. \documentclass{kais} \begin{document} \section{New Section} \label{sec:new} In the methods, abc \dots abc xyz \dots \begin{table} \small \centering \begin{minipage}{\textwidth} \centering \begin{tabular}{|c|c|c|c|} \hline {Id} & {Age} & {Lab-tests} & {Time-in-Hospital} \\ \hline 1 & 45 & 13 & 35 \\ \hline 2 & 35 & 7 & 20 \\ \hline 3 & 30 & 5 & 25 \\ \hline 4 & 55 & 10 & 28 \\ \hline 5 & 40 & 14 & 38 \\ \hline \end{tabular}% \caption{\label{tab:ptabular} Patients} \end{minipage} \end{table} \end{document} – Faaiz Jul 12 '18 at 9:02
• @Bernard \documentclass{kais} \begin{document} \section{New Section} \label{sec:new} In the methods, abc \dots abc xyz \dots \begin{table} \small \centering \begin{minipage}{.5\textwidth} \centering \begin{tabular}{|c|c|c|c|} \hline {Id} & {Age} & {Lab-tests} & {Time-in-Hospital} \\ \hline 1 & 45 & 13 & 35 \\ \hline 2 & 35 & 7 & 20 \\ \hline 3 & 30 & 5 & 25 \\ \hline 4 & 55 & 10 & 28 \\ \hline 5 & 40 & 14 & 38 \\ \hline \end{tabular}% \caption{\label{tab:ptabular} Patients} \end{minipage} \end{table} \end{document} – Faaiz Jul 12 '18 at 9:03

This seems to work, despite the warnings on ‘caption not aware ofthe document class’:

\documentclass{kais}
\usepackage{array}
\usepackage{floatrow, caption}

\begin{document}

\section{New Section} \label{sec:new}

In the methods, abc \dots abc xyz \dots

\begin{table}
\captionsetup{singlelinecheck = false}
\setlength{\tabcolsep}{5pt}
\centering
\small
\begin{floatrow}
\ttabbox[\FBwidth]{
\begin{tabular}{|c|c|c|c|}
\hline
{Id} & {Age} & {Lab-tests} & {Time-in-Hospital} \\
\hline
1 & 45 & 13 & 35 \\
\hline
2 & 35 & 7 & 20 \\
\hline
3 & 30 & 5 & 25 \\
\hline
4 & 55 & 10 & 28 \\
\hline
5 & 40 & 14 & 38 \\
\hline
\end{tabular}}
{\caption{\label{tab:ptabular} Patients}}
\ttabbox[\FBwidth]{
\begin{tabular}{|c|c|c|c|}
\hline
{Id} & {Age} & {Lab-tests} & {Time-in-Hospital} \\
\hline
1 & 45 & 13 & 35 \\
\hline
2 & 35 & 7 & 20 \\
\hline
3 & 30 & 5 & 25 \\
\hline
4 & 55 & 10 & 28 \\
\hline
5 & 40 & 14 & 38 \\
\hline
\end{tabular}}
{\caption{\label{tab:ptabular-a} Patients}}
\end{floatrow}
\end{table}

\end{document}


• Thanks for your reply. It work in sample document. But it does't work in my actual document. When i add \usepackage{array} , it gives me error : ! Missing # inserted in alignment preamble. <to be read again> \cr l.85 There should be exactly one # between &'s, when an \halign or \valign is being set up. – Faaiz Jul 12 '18 at 10:22
• @Berbard, Nevertheless i appreciate your time and effort. I think my issue is not resolvable. Following is the list of all packages that i use in my document. \usepackage{wrapfig,epsf} \usepackage{tikz} \usepackage{xcolor} \usetikzlibrary{shapes} \usepackage{graphicx} \usepackage{hyperref,url} \usepackage[sort,numbers]{natbib} \usetikzlibrary{tikzmark,calc} – Faaiz Jul 12 '18 at 10:25
• @Faaiz: Could you post a small (complete) document reproducing the problem? I'll add that using the lines from booktabs or those from hhline or from boldlines  also work. Not sure it's related, but epsf is obsolete (\includegraphics does the job) and hyperref should be the last loaded package, with very few exceptions; – Bernard Jul 12 '18 at 15:06