[Tex/LaTex] How to align table so that it doesn’t overflow the page horizontally

tables

I need this to fit in page, but it overflows! I tried reference on the link

  1. How to shrink a table automatically so that it fits onto a page?
  2. Latex table goes out of page border

but no success.
Here's the table.

\begin{center}
 \begin{tabular}{|1|c|c|c|c|c|} 
 \hline
 ID & Test Name & Test Description & Input & Expected Output & Actual Output \\ [0.5ex]
 \hline
 1 & Arduino & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED\\ 
 \hline
 1 & Arduino & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED\\
 \hline
1 & Arduino & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED\\
 \hline
1 & Arduino & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED\\
 \hline
\end{tabular}
\tabcap{Sound Limit in different zones}
\end{center}

Best Answer

Two solutions based on tabularx. The second uses the booktabs package, with only $3$ horizontal rules:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{array, caption, tabularx,  ragged2e,  booktabs}

\begin{document}\

\noindent\setlength\tabcolsep{4pt}%
\begin{tabularx}{\linewidth}{|l|c|*{4}{>{\RaggedRight\arraybackslash}X|}}
  \hline
  ID & Test Name & Test Description           & Input                & Expected Output              & Actual Output   \\ [0.5ex]
  \hline
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \hline
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \hline
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \hline
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \hline
\end{tabularx}
\captionof{table}{Sound Limit in different zones}
\vskip1cm

\noindent\setlength\tabcolsep{4pt}%
\begin{tabularx}{\linewidth}{lc*{4}{>{\RaggedRight\arraybackslash}X}}
  \toprule
  ID & Test Name & Test Description           & Input                & Expected Output              & Actual Output   \\ [0.5ex]
  \midrule
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \addlinespace
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \addlinespace
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \addlinespace
  1  & Arduino   & Code burning and executing & Pin controlled write & blinking LED on intended pin & Blinking of LED \\
  \bottomrule
\end{tabularx}
\captionof{table}{Sound Limit in different zones}

\end{document} 

enter image description here

Related Question