# LaTeX table not working

I am trying to create a table using LaTeX, but it is not working properly. Some problems are: It is overflowing on the next page, the text is scattered and the alignment is bad. I also want to add more text in the column name idea.

Please find the code given below.

\documentclass{article}

\begin{document}

\begin{center}

\begin{tabular}{|p{0.4cm}||p{2cm}|p{2cm}|p{2cm}| p{2cm}|p{2cm}|p{2cm}|}

\hline

\multicolumn{7}{|c|}{\textbf{Data Structures}} \\

\hline

\textbf{No} & \textbf{Sigma name and all}  & \textbf{Idea}& \textbf{Construct Time(Runtime Time)} & \textbf{Construct Time (Space)} & \textbf{Searching data (Query)} & \textbf{Search head (Space)}\\
\hline

1  & ABCD    &  These algorithms achieve performance better than the classic &   O(NLkt) & O(nL)&O(L(kt + dnp)&O(1)\\ \hline

2&   FGH  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces & $O(dn \log n)$ & $O(dn)$ &222& $O(1)$\\ \hline

3&LMPQ & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces &  008 & 666 & 242&333\\ \hline

4    & RSTV & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces &  012 & 888 & 333&55\\ \hline

5&   ZMNQ & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces &016 & 888 & 444&343\\ \hline

6& WORP  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces and MBR   &020 &555 & 444&333\\ \hline

7& MNPO  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces. Search based on data pruning and the radius of nodes.&024 & 888 &224&342\\ \hline
\hline

\end{tabular}

\end{center}

\end{document}

• Not everything that fits in software tables (like excel, where sliders etc. are) will fit on the paper. May 26 at 5:56
• See tex.stackexchange.com/questions/332902/… (your question is duplicate to it). You should tell us, if you can change page layout, can table be rotated to landscape , minimal allowed font size, can column headers be shortened, etc. May 26 at 6:16
• Welcome to TeX.SE.
– Mico
May 26 at 7:33

One possible solution:

• wider \textwidth determined by use of the geometry package
• footnotesize font size
• different widths of columns
• use of the tabularray package
\documentclass{article}
\usepackage{geometry}
\usepackage{microtype}
\usepackage{tabularray}

\begin{document}

\begin{center}
\footnotesize
\begin{tblr}{hlines, vlines,
colspec = {c X[0.5, c] X[2.2, j] *{4}{X[0.7, c]}},
colsep = 3pt,
row{1,2} = {font=\bfseries, c, m}
}
\SetCell[c=7]{c}    Data Structures
&       &       &       &       &       &                       \\
No      & Sigma name and all
& Idea  & Construct Time (Runtime Time)
& Construct Time (Space)
& Searching data (Query)
1  & ABCD      &  These algorithms achieve performance better than the classic
& O(NLkt)
& O(nL) & O(L(kt + dnp)
& O(1)                   \\
2  & FGH       & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
& $O(dn \log n)$
& $O(dn)$
& 222   & $O(1)$                \\

3  & LMPQ      & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
& 008   & 666   & 242   & 333                   \\
4    & RSTV    & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
&  012  & 888   & 333   & 55                    \\
5      & ZMNQ  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
& 016   & 888   & 444   & 343                   \\
6      & WORP  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces and MBR
& 020   & 555   & 444   & 333                   \\
7      & MNPO  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces. Search based on data pruning and the radius of nodes.
& 024   & 888   & 224   & 342                   \\
\end{tblr}
\end{center}

\end{document}


(grey lines are page borders)

Addendum: Yes, this table can be set on classical way, which can be compiled also on Overleaf. Code as well result are lef elegant, but solution works:


\documentclass{article}
\usepackage{geometry}
\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{tabularx}
\newcolumntype{C}[1]{>{\hsize=#1\hsize\linewidth=\hsize%
\Centering}X}
\newcolumntype{L}[1]{>{\hsize=#1\hsize\linewidth=\hsize%
\RaggedRight\hspace{0pt}}X}

\begin{document}

\begin{center}
\footnotesize
\setlength\tabcolsep{3pt}
\begin{tabularx}{\textwidth}{|c | C{0.7} | L{2.5} | *{4}{C{0.7}|} }
%
\hline
\multicolumn{7}{|c|}{\textbf{Data Structures}}                                   \\
\hline
\textbf{No}
& \textbf{Sigma name and all}
& \centering\textbf{Idea}
& \textbf{Construct Time (Runtime Time)}
& \textbf{Construct Time (Space)}
& \textbf{Searching data (Query)}
\\
\hline
1  & ABCD      &  These algorithms achieve performance better than the classic
& O(NLkt)
& O(nL) & O(L(kt + dnp)
& O(1)                   \\
\hline
2  & FGH       & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
& $O(dn \log n)$
& $O(dn)$
& 222   & $O(1)$                \\
\hline
3  & LMPQ      & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
& 008   & 666   & 242   & 333                   \\
\hline
4    & RSTV    & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
&  012  & 888   & 333   & 55                    \\
\hline
5      & ZMNQ  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces
& 016   & 888   & 444   & 343                   \\
\hline
6      & WORP  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces and MBR
& 020   & 555   & 444   & 333                   \\
\hline
7      & MNPO  & is an algorithm for solving the approximate or exact Near Neighbor Search in high dimensional spaces. Search based on data pruning and the radius of nodes.
& 024   & 888   & 224   & 342                   \\
\hline
\end{tabularx}
\end{center}

\end{document}


• Thanks Zarko! The content in the idea column is covered by black strip. How to remove it?
– Shi
May 26 at 8:41
• @Shi, in my answer hasn't black strip ;-). How you compile my MWE? Do you use Overleaf? Overleaf has installed (to) old tabularray version which may make troubles. May 26 at 9:16
• @Shi do you mean a black strip to the right of that column? Might be an overfull-rule, do you compile using the draft option, or with \overfullrule > 0pt? May 26 at 10:53
• I am using overleaf
– Shi
May 26 at 12:50
• @Skillmon Yes black strip
– Shi
May 26 at 12:50