Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Based on Writing descriptions of columns of table

\documentclass{article}
\usepackage{polski}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{figure}\label{fig:ieee754single}
\centering\sf\setlength{\tabcolsep}{1.45pt}
\begin{tabular}{|*{32}{c|}}
\multicolumn{32}{|l}{\small  Bit}\\
\multicolumn{1}{|c}{\footnotesize  31}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  24}&
\multicolumn{1}{|c}{\footnotesize  23}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  16}&
\multicolumn{1}{|c}{\footnotesize  15}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  8}&
\multicolumn{1}{|c}{\footnotesize  7}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  0}\\
\hline
S &
E & E & E & E & E & E & E & E &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M \\
\hline
\multicolumn{1}{|c|}{}&
\multicolumn{8}{c|}{Wykładnik} &
\multicolumn{23}{c|}{Mantysa} \\
\cline{2-32}
\multicolumn{5}{|c}{\raisebox{-0.3ex}{Znak}} & \multicolumn{27}{c}{}\\
\cline{1-5}
\end{tabular}
\rm\caption{IEEE754 single}
\end{figure}
\end{document}

How can I force column widths to be the same. I like the width of E under 23.

share|improve this question
    
possible duplicate of columns width of array environment –  Werner May 8 '12 at 18:23
    
Try it with p{<width>} instead of c as column specifier. –  Martin Scharrer May 8 '12 at 18:23
    
\begin{tabular}{|*{32}{p{\widthof{M}}|}} will work better than an E as the M is wider. This requires the calc package. –  Peter Grill May 8 '12 at 18:25
    
Martin, using p works for width setting but I lose centering of letters inside cells... Peter, ...but '23' is wider than 'M'... –  Ichibann May 8 '12 at 18:27
    
Then try >{\centering\arraybackslash}p{<width>}. –  Martin Scharrer May 8 '12 at 18:27

2 Answers 2

up vote 7 down vote accepted

You can set the column width only with the paragraph p column type. In order to get centering you need to add \centering before, usually followed by \arraybackslash to restore the tabular meaning of \\. You can do so using the >{..} column specifier provided by the array package. It also allows you to define you own custom column types. I would suggest you do:

\usepackage{array}
\newcolumntype{C}{>{\centering\arraybackslash}p{2ex}}

and then use C instead of c. There is also a lower-level TeX way to do it, which I added below. It lowers the text a little, which looks better IMHO.

\documentclass{article}
%\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{array}

% Normal LaTeX way: \newcolumntype{C}{>{\centering\arraybackslash}p{2ex}}
% Using lower-level TeX commands:
\newcolumntype{C}{>{\lower.2ex\hbox to 2ex\bgroup\hss}c<{\hss\egroup}}
\begin{document}
\begin{figure}
\centering\sf\setlength{\tabcolsep}{1.45pt}
\begin{tabular}{|*{32}{C|}}
\multicolumn{32}{|l}{\small  Bit}\\
\multicolumn{1}{|c}{\footnotesize  31}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  24}&
\multicolumn{1}{c}{\footnotesize  23}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  16}&
\multicolumn{1}{c}{\footnotesize  15}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  8}&
\multicolumn{1}{c}{\footnotesize  7}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  0}\\
\hline
S &
E & E & E & E & E & E & E & E &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M \\
\hline
\multicolumn{1}{|c|}{}&
\multicolumn{8}{c|}{Wykładnik} &
\multicolumn{23}{c|}{Mantysa} \\
\cline{2-32}
\multicolumn{5}{|c}{\raisebox{-0.3ex}{Znak}} & \multicolumn{27}{c}{}\\
\cline{1-5}
\end{tabular}
\rmfamily
\caption{IEEE754 single}
\label{fig:ieee754single}
\end{figure}
\end{document}

Please also note my other changes (\label after \caption, \rmfamily instead of \rm, ..).

Result

share|improve this answer
    
Why \label after \caption and what is a difference between \rm and \rmfamily? –  papciuch May 8 '12 at 18:46
    
\label always labels the last command which increases an official LaTeX counter (\section, \caption, etc.) and will label the wrong thing if not after or inside \caption. \rm is an old LaTeX2.0 macro and \rmfamily the correct LaTeX2e macro which supports the modern font selection scheme. See Does it matter if I use \textit or \it, \bfseries or \bf, etc. for more details. –  Martin Scharrer May 8 '12 at 18:49
    
So should I use \sfseries in \centering\sf\setlength{\tabcolsep}{1.45pt}? –  papciuch May 8 '12 at 18:51
1  
This looks very nice. Too bad 64-bit double will not fit on the page. Eccept... I do it other way. –  papciuch May 8 '12 at 19:04
    
@papciuch: Yes, \sfseries instead of \sf. I didn't see that. –  Martin Scharrer May 8 '12 at 19:06

Here you have 32- and 64-bit representation of float and double variable. If you like ± instead of Znak it will be good one. I think so ;). Do you like it?

\documentclass{article}
%\usepackage{polski}
\usepackage[utf8]{inputenc}
\usepackage{array}

% Normal LaTeX way: \newcolumntype{C}{>{\centering\arraybackslash}p{2ex}}
% Using lower-level TeX commands:
\newcolumntype{C}{>{\lower.2ex\hbox to 2ex\bgroup\hss}c<{\hss\egroup}}
\begin{document}
\begin{figure}
\centering\sffamily\setlength{\tabcolsep}{1.45pt}
\begin{tabular}{|*{32}{C|}}
\multicolumn{32}{l}{\raisebox{-0.3ex}{\small Bit}}\\
\multicolumn{1}{|c}{\footnotesize  31}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  24}&
\multicolumn{1}{c}{\footnotesize  23}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  16}&
\multicolumn{1}{c}{\footnotesize  15}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  8}&
\multicolumn{1}{c}{\footnotesize  7}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  0}\\
\hline
S &
E & E & E & E & E & E & E & E &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M \\
\hline
\multicolumn{1}{|c|}{\raisebox{-0.2ex}{$\pm$}}&
\multicolumn{8}{c|}{\raisebox{-0.2ex}{\small Wykładnik}} &
\multicolumn{23}{c|}{\raisebox{-0.2ex}{\small Mantysa}} \\
\hline
\end{tabular}
\rmfamily
\caption{IEEE754 single}
\label{fig:ieee754single}
\end{figure}

\begin{figure}
\centering\sffamily\setlength{\tabcolsep}{1.45pt}
\begin{tabular}{|*{32}{C|}}
\multicolumn{32}{l}{\raisebox{-0.3ex}{\small Bit}}\\
\multicolumn{1}{|c}{\footnotesize  63}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  56}&
\multicolumn{1}{c}{\footnotesize  55}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  48}&
\multicolumn{1}{c}{\footnotesize  47}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  40}&
\multicolumn{1}{c}{\footnotesize  39}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  32}\\
\hline
S &
E & E & E & E & E & E & E & E &
E & E & E &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M &
M & M & M & M\\
\hline
\multicolumn{1}{|c|}{\raisebox{-0.2ex}{$\pm$}}&
\multicolumn{11}{c|}{\raisebox{-0.2ex}{\small Wykładnik}} &
\multicolumn{20}{c|}{\raisebox{-0.2ex}{\small Mantysa}} \\
\hline
\multicolumn{32}{c}{}\\[-1.2ex]
\multicolumn{1}{|c}{\footnotesize  31}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  24}&
\multicolumn{1}{c}{\footnotesize  23}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  16}&
\multicolumn{1}{c}{\footnotesize  15}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  8}&
\multicolumn{1}{c}{\footnotesize  7}&\multicolumn{6}{c}{}&\multicolumn{1}{c|}{\footnotesize  0}\\
\hline
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M &
M & M & M & M & M & M & M & M\\
\hline
\multicolumn{32}{|c|}{\raisebox{-0.2ex}{\small Mantysa}} \\
\hline
\end{tabular}
\rmfamily
\caption{IEEE754 double}
\label{fig:ieee754double}
\end{figure}
\end{document}

enter image description here

share|improve this answer
    
Yes, I like it :) –  papciuch May 8 '12 at 20:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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