2

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}

Ingmar
  • 6,690
  • 5
  • 26
  • 47
Shi
  • 55
  • 1
    Not everything that fits in software tables (like excel, where sliders etc. are) will fit on the paper. – wipet May 26 '22 at 05:56
  • See https://tex.stackexchange.com/questions/332902/my-table-doesnt-fit-what-are-my-options (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. – Zarko May 26 '22 at 06:16
  • Welcome to TeX.SE. – Mico May 26 '22 at 07:33

1 Answers1

5

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) & Search head (Space) \ 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}

enter image description here

(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)} & \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 \end{tabularx} \end{center}

\end{document}

enter image description here

Zarko
  • 296,517
  • Thanks Zarko! The content in the idea column is covered by black strip. How to remove it? – Shi May 26 '22 at 08: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. – Zarko May 26 '22 at 09: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? – Skillmon May 26 '22 at 10:53
  • I am using overleaf – Shi May 26 '22 at 12:50
  • @Skillmon Yes black strip – Shi May 26 '22 at 12:50
  • Is it possible to modify above code so that it works in overleaf – Shi May 26 '22 at 12:54
  • @Shi, I'm afraid that no. As I'm informed, they will upgrade their installation sometime around October and than it will works as it. However, ask their support, if you can locally add last version of tabularray package. (I'm not use Overleaf). Another option is, that you locally install MiKTeX or Texlive and become independent from Overleaf. – Zarko May 26 '22 at 13:59
  • @Shi, see Addendum to answer. – Zarko May 26 '22 at 14:20