2

I know this may sound stupid of a question but I am a very beginner in LaTeX.

\begin{table}[H]
    \centering
    \begin{tabular*}{\textwidth}{|c|}
        \hline                                
        \begin{tabular}[c]{@{}l@{}}           
        \textbf{\textbf{Description sommaire}}:        
    \end{tabular} 
    \\ \hline
    \end{tabular*}
\end{table}

I am trying to force a table into page width. I used {tabular*} for that and it worked. But now I have an issue with borders. The left border is displayed normally however the right one is misplayed.

enter image description here

My table has only one column and I want the right border to be on the right end of the table. How can I do that?

  • If your tabular-like material contains a single column, you shouldn't be using a tabular* environment to achieve your typesetting objective. tabular* is designed to achieve the desired width (here: \textwidth) by dynamically enlarging the amount of intercolumn whitespace. For this setup to have any chance to work, there must be at least two columns. You really should be looking into using a tabularx environment. – Mico Apr 29 '17 at 22:20
2

tabular* has a special syntax which must be followed to take advantage of its capability to expand the table to the whole textwidth. Here is the required syntax:

\begin{table}[htbp]
    \centering
    \begin{tabular*}{\textwidth}{|c|@{\extracolsep{\fill}}c|}
        \hline                                          
        \textbf{\textbf{Description sommaire}}: &  \\ \hline
    \end{tabular*}
\end{table}

enter image description here

Otherwise, just use the more-common tabularx environment (which I recommend):

\begin{table}[htbp]
    \centering
    \begin{tabularx}{\textwidth}{|c|X|}
        \hline                                          
        \textbf{\textbf{Description sommaire}}: &  \\ \hline
    \end{tabularx}
\end{table}

this gives the same result plus text-wrapping as a bonus.

  • I feel that the OP is searching really for a single cell as header of plain text outside the float. If this is true a float with tpb options will be very dangerous. – Fran Apr 29 '17 at 4:46
2

Are you trying to make a framed section-like title?

Because then, make a float (a table) is the worse idea possible. This can displace the title to anywhere. Although with [H] option you make that the float does not float, still a table environment is completely unnecessary. May be you are using it to avoid indentation of the table a add vertical spaces, but this can be solved better without a float (respectively, with \noindent and some vertical spacing command as \bigskip, or maybe set \parindent to 0pt and \parskip to some more).

Nested tabulars do not make sense either. One (simple) tabular is enough, or a framed box (\fbox{}) that can take the line width less the space used by the framed box, as a \makebox, a \parbox, or a minipage environement, may be in a section redefinition or alternatively, use a very configurable boxing package as mdframed or tcolorbox, or simply write some \vrules and \hrules around, without making any box.

The example show 5 of the many alternatives. Use the one that makes you happy.

mwe

\documentclass{article}
% Padding of \fbox{} 
\setlength\fboxsep{.5em}

% Some dummy text between solutions, just to see the layout 
\def\loreipsum{Lorem ipsum dolor sit amet, consectetur adipiscing    
elit. Fusce elit lectus, dapibus eget pellentesque eu, ultricies 
vel turpis. Cras quis convallis nibh.}

% for solution 2 only
\makeatletter
\newcommand\fsection{\@startsection{section}{1}{\z@}%
{1em}{1em}{\bfseries\framedbox}}
\makeatother
\newcommand*\framedbox[1]{\noindent%
\fbox{\parbox{\dimexpr\columnwidth-2\fboxsep}{#1}}}

% for solution 5 only
\usepackage{mdframed}


\begin{document}

\loreipsum

% solution 1
\bigskip\hrule
\noindent
\vrule height 12pt depth 6pt width 0.4pt 
{ \bfseries Description sommaire}\hfill\vrule
\hrule\bigskip

\loreipsum

% solution 2
\fsection*{Description sommaire} 

\loreipsum

% solution 3
\bigskip
\noindent\fbox{\makebox[\dimexpr\linewidth-2\fboxsep-2\fboxrule][l]
{\textbf{Description sommaire}}}\bigskip

\loreipsum

% solution 4
\bigskip
{\renewcommand\arraystretch{1.4}\setlength\tabcolsep{.5em}
\noindent\begin{tabular}%
{|p{\dimexpr\linewidth-2\tabcolsep-2\arrayrulewidth}|}\hline
\textbf{Description sommaire} \\\hline
\end{tabular}}
\bigskip

\loreipsum

% solution 5
\begin{mdframed} 
\textbf{Description sommaire}: 
\end{mdframed}

\loreipsum

\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.