[Tex/LaTex] Set default width of \shadowbox to line, not column, width

boxeslyxwidth

When I insert a shadowbox using Lyx (Insert>Box>Drop Shadow) the width is specified as 100% of column width (1\columnwidth). This is the source code it generates:

\shadowbox{\begin{minipage}[t]{1\columnwidth}%
My shadowbox content goes here.%
\end{minipage}}

The column width seems like a poor default choice since any indentation moves the shadowbox into the right-hand margin.* I'd like to make the line width (1\linewidth) the default width so boxes only extend up to the right-hand margin.

I tried redefining the \shadowbox command in my preamble but the parameter I'm trying to change is actually part of the \minipage inside the shadowbox and I haven't figured out how to access it.

I've also tried redefining the width of the frame based on this excerpt from the documentation:

\shadowbox

The width of the frame is \fboxrule (the same as with \fbox). The width of the shadow is \shadowsize (default: 4pt).

by adding this line to my preamble:

\setlength{\fboxrule}{\linewidth}

It did not produce the results I expected (below). Is there a straightforward way to specify shadowboxes use line, not column, width by default?

Results of setting \fboxrule to \linewidth


Footnotes

* The shadowbox command was redefined in my preamble to ignore paragraph indenting

\let\oldshadowbox\shadowbox
\renewcommand{\shadowbox}[1]{%
  \noindent \oldshadowbox{#1}}

But sometimes indentation is preferable such as when placing shadowboxes under list items

Best Answer

I'd suggest you to use \linegoal from the linegoal package (requires two compilations). Of course, you also need to take into account the padding of the box and the width of the shadow, so the width would be

-\fboxsep-\shadowsize+\linegoal

A complete example:

\documentclass{article}
\usepackage{fancybox}
\usepackage{linegoal}
\usepackage{showframe}

\begin{document}

\noindent\shadowbox{\begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}%
My shadowbox content goes here.%
\end{minipage}}

some test text\shadowbox{\begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}%
My shadowbox content goes here.%
\end{minipage}}

some longer test text for the example\shadowbox{\begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}%
My shadowbox content goes here.%
\end{minipage}}

\end{document}

enter image description here

And you can make this the default behaviour using a command:

\documentclass{article}
\usepackage{fancybox}
\usepackage{linegoal}

\let\Oldshadowbox\shadowbox

\renewcommand\shadowbox[1]{%
  \Oldshadowbox{%
  \begin{minipage}[t]{\dimexpr-\fboxsep-\shadowsize+\linegoal\relax}
  #1
  \end{minipage}}%
}  

\begin{document}

\noindent\shadowbox{My shadowbox content goes here.}

some test text\shadowbox{My shadowbox content goes here.}

some longer test text for the example\shadowbox{My shadowbox content goes here My shadowbox content goes here My shadowbox content goes here My shadowbox content goes here My shadowbox content goes here.}

\end{document}

enter image description here

Related Question