1

I have two column based structure. I want table to fit data in one column but it overflows the other column enter image description here

Code which i write is following

\newline
 \vspace*{1 cm}
  \newline
   \begin{tabular} { |c|  }
    \hline
    Decrypted-Data \\
    \hline
    0000000 0000100 0000000 0000101  0011111 0101111 1001001 1111101\\
    \hline
   \end{tabular}
   \newline
   \vspace*{1 cm}
    \newline
2
  • apparently your table is to wide. you can make it shorter on many ways, for example broke cell content into two line or use smaller font.
    – Zarko
    Dec 7, 2016 at 18:51
  • why use a tabular at all if you only have one column? Dec 7, 2016 at 20:27

2 Answers 2

1

You are using an 'c' column. That means, the width of the column will grow with the length of the data, you want to put into that cell. LaTeX won't break the cell content into multiple lines.

@Zarko wrote some hints, e. g. to use a smaller font. Personally, I don't think, that it is a good idea, to decrease the font size.

The first recommendation would be, to use another column declaration. For example, the p column identifier will produce a column with a given width. LaTeX will break the cell content into lines, to ensure, it won't be longer than the column is wide.

Unfortunately, this column will be justified. To prevent that, you should load the array package and use the >{} command, to use a flush left or right environment instead.

I'd say, this should do the trick

\begin{tabular} { |>{\raggedright\hspace{0pt}p{0.8\linewidth}|  }
\hline
Decrypted-Data \\
\hline
0000000 0000100 0000000 0000101  0011111 0101111 1001001 1111101\\
\hline
\end{tabular}

(I am not sure myself, if \hspace{0pt} is necessary in this case, as you obviously don't want LaTeX to cut in the middle of the tuples. You may leave it away.)

If you want to avoid fiddling with the exact width definition of your p-column, than the tabularx package should do the trick for you. You could than use

\begin{tabularx}{\linewidth} { |>{\raggedright\hspace{0pt}X|  }
\hline
Decrypted-Data \\
\hline
0000000 0000100 0000000 0000101  0011111 0101111 1001001 1111101\\
\hline
\end{tabularx}

In this case, the resulting tabular will use all the linewidth (roughly half the \textwidth) and the X-column will fill up all available space. If you happen to have two columns, just use XX and both columns will sum up all the space, each column being as wide as the other.

Have fun

Jan

1
  • In comment I mentioned smaller fonts as possible solution, but in my answer I didn't use it! And by the way, your examples doesn't works. Correct beginning of tables are: \begin{tabular}{|>{\raggedright\arraybackslash}p{0.8\linewidth}|} and \begin{tabularx}{\linewidth}{|>{\raggedright\arraybackslash}X|}
    – Zarko
    Dec 20, 2016 at 19:53
0

See if one of the following examples is acceptable to you:

enter image description here

\documentclass{ieeetran}
\usepackage{array}
\usepackage{lipsum}

\begin{document}
\lipsum[2]
    \begin{center}
\renewcommand\arraystretch{1.2}
   \begin{tabular} { |>{\ttfamily}c|  }
    \hline
\textrm{Decrypted-Data} \\
    \hline
0000000 0000100 0000000 0000101 \\
0011111 0101111 1001001 1111101\\
    \hline
   \end{tabular}
    \end{center}
or
    \begin{center}
\renewcommand\arraystretch{1.2}
   \begin{tabular} {@{}>{\footnotesize}r |>{\ttfamily}c|  }
    \cline{2-2}
            &   \textrm{Decrypted-Data} \\
    \cline{2-2}
 0 -- 31    &   0000000 0000100 0000000 0000101 \\
32 -- 63    &   0011111 0101111 1001001 1111101\\
    \cline{2-2}
   \end{tabular}
    \end{center}
\lipsum
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.