[Tugindia] still problem with \colorbox.......
E. Krishnan
ekmath at md5.vsnl.net.in
Sun Nov 30 03:15:46 CET 2003
On Sat, 29 Nov 2003, Jagadeesh Bhaskar wrote:
> i was actually trying to get section headings enveloped in gray box.
> when i filled like that, though i got color box of the whole width of the
> page as i required,
>
> now what i need is how to include the section numbering also in the same
> \colorbox of page-width.
> i also need to provide a thick horizontal line, \hline didn't work, under
> section headings; which extends in width more than the actual width of text
> like below
>
> ==================
> heading
> __________________
> contentadfadfadfa
> asdfasdfasdfasdfa
> adfasdfasdfasdfas
I don't if this is really what you want, but give this a try.
\documentclass{article}
\usepackage{color}
\usepackage{titlesec}
\usepackage{calc}
\newlength{\seclen}
\newlength{\secaddlen}
\definecolor{MyGray}{gray}{0.75}
\newcommand{\secbox}[1]{%
\settowidth{\seclen}{\thesection\quad#1}
\setlength{\secaddlen}{\textwidth-\seclen-7pt}
\colorbox{MyGray}{\thesection\quad#1\hspace{\secaddlen}}}
\titleformat{\section}%
[display]%
{\titlerule
\large\bfseries}%
{}%
{0pt}%
{\secbox}
[\vspace{2ex}
\titlerule]
\begin{document}
\section{The first section}
This is the first section
\end{document}
Please see the documentation of "titlesec" package for more information.
--
Krishnan
More information about the tugindia
mailing list