The thickness of \fbox
in LaTeX can be changed by using \fboxrule
. But I want different thickness for different sides. Basically I want to write a text with only a border in top and no where. So I am using \fbox
, but it gives a box around the whole text. Is there any suitable method for this?
[Tex/LaTex] \fbox thickness different for different size
boxesrules
Related Solutions
Any box commands in math mode need to be set in all styles so TeX can pick the right one later; the \mathchoice
command is what you need here. See my rant against \over
on this site the other day:-) If you just use \hbox{$...$}
you are starting a fresh math list at text size even in subscript position.
You can re-assert the correct spacing around your construct using \mathbin
\mathop
and friends, This could be done automatically by looking up the\mathcode
of the character you are boxing. Inspecting bm.sty
might be helpful, which does this to re-assert the correct math class after making things bold, but the issues are similar.
It's a bit late to re-create bm
interrogation of \mathcode
so this just looks at special cases \cdot
and +
but otherwise does something plausible I suspect
UPDATE At the end I place a version that does automatically pick up the math class from character tokens, things like \cdot
defined by \mathchar
and things like \log
with explicit \mathop
. I will leave the original version in place as the math class detection probably obscures the logic of the measuring which was perhaps the main part of the question.
\documentclass{article}
\usepackage{amsmath,color}
\makeatletter
\def\fb@cdot{\cdot}
\def\fb@p{+}
\def\@mfbox#1{%
\def\fb@{#1}%
\ifx\fb@\fb@cdot\mathbin\fi
\ifx\fb@\fb@p\mathbin\fi
{\text{\fboxsep\z@\colorbox{yellow}{$\m@th#1$}}}}
\def\@tfbox#1{{\fboxsep\z@\colorbox{yellow}{#1}}}
\def\fillbox#1{\ifmmode\expandafter\@mfbox\else\expandafter\@tfbox\fi{#1}}
\begin{document}
\vskip1em
$\fillbox{p}_{\fillbox{x}}
\mathrel{\stackrel{\fillbox{_{~+}}}{\fillbox{\leftarrow}}}
\fillbox{(}\fillbox{\frac{\fillbox{1}}{\fillbox{2}}}\fillbox{\cdot}
\fillbox{a}_{\fillbox{x}}\fillbox{\cdot}%
\fillbox{\Delta}\fillbox{t}^{\fillbox{2}}\fillbox{)} \fillbox{+}
\fillbox{(}\fillbox{v}_{\fillbox{x}}\fillbox{\cdot}%
\fillbox{\Delta}\fillbox{t}\fillbox{)}$\fillbox{;}\par
$\fillbox{v}_{\fillbox{x}}
\mathrel{\stackrel{\fillbox{_{~+}}}{\fillbox{\leftarrow}}}
\fillbox{a}_{\fillbox{x}}\fillbox{\cdot}%
\fillbox{\Delta}\fillbox{t}$\fillbox{;}\par
\vskip1em
$p_x \mathrel{\stackrel{_{~+}}{\leftarrow}}
(\frac{1}{2}\cdot a_x\cdot\Delta t^2) + (v_x\cdot\Delta t)$;\par
$v_x \mathrel{\stackrel{_{~+}}{\leftarrow}} a_x\cdot\Delta t$;\par
\end{document}
Version using bm
-style math class detection.
\documentclass{article}
\usepackage{amsmath,color}
\makeatletter
\def\fb@eat#1#2#3#4#5{\futurelet\fb@let@token\fb@eat@}
\def\fb@eat@#1\fb@eat{%
\ifx\fb@let@token\bgroup
\else\ifx\fb@let@token\mathop
\mathop
\else\ifx\fb@let@token\mathbin
\mathbin
\else\ifx\fb@let@token\mathrel
\mathrel
\else\ifx\fb@let@token\mathopen
\mathopen
\else\ifx\fb@let@token\mathop
\mathop
\else\ifx\fb@let@token\mathpunct
\mathpunct
\else\ifcat.\ifcat a\noexpand\fb@let@token.\else\noexpand\fb@let@token\fi
\afterassignment\fb@mathchar\count@\mathcode`#1\relax\fb@eat
\else\ifx\fb@let@token\mathchar
\afterassignment\fb@mathchar\expandafter\count@\@gobble#1\relax\fb@eat
\else
\xdef\meaning@{\meaning\fb@let@token}%
\expandafter\fb@mchar@test\meaning@""\@nil
\fi\fi\fi\fi\fi\fi\fi\fi\fi
}
\def\@mfbox#1{%
\begingroup
\let\protect\empty
\expandafter\fb@eat\romannumeral`\Q#1\relax\fb@eat
\ifcase\count@
\or
\mathop\or
\mathbin\or
\mathrel\or
\mathopen\or
\mathclose\or
\mathpunct\or
\fi
{\text{\fboxsep\z@\colorbox{yellow}{$\m@th#1$}}}%
\endgroup}
\edef\fb@mchar@{\meaning\mathchar}
\def\fb@mchar@test#1"#2"#3\@nil{%
\xdef\meaning@{#1}%
\ifx\meaning@\fb@mchar@
\count@"#2\relax
\fb@mathchar\fb@eat
\fi
}
\def\fb@mathchar#1\fb@eat{%
\divide\count@"1000 }
\def\@tfbox#1{{\fboxsep\z@\colorbox{yellow}{#1}}}
\def\fillbox#1{\ifmmode\expandafter\@mfbox\else\expandafter\@tfbox\fi{#1}}
\begin{document}
$a-b$
$a{-}b$
$a\fillbox{-}b$
$\log x + \mathrm{log}x$
$\fillbox{\log} \fillbox{x} \fillbox{+} \fillbox{\mathrm{log}}\fillbox{x}$
$\fillbox{0}$
$ a \cdot b {\cdot} c$
$ a \fillbox{\cdot} b \fillbox{{\cdot}}c $
$a \fillbox{\mathchar"2201} b \fillbox{{\mathchar"2201}} c $
$ a - b < \alpha $
$\fillbox{a} \fillbox{-} \fillbox{b} \fillbox{<} \fillbox{\alpha}$
$\fillbox{a+b}$
$a = \sqrt{h}$
$a = \fillbox{\sqrt{h}}$
\vskip1em
$\fillbox{p}_{\fillbox{x}}
\mathrel{\stackrel{\fillbox{_{~+}}}{\fillbox{\leftarrow}}}
\fillbox{(}\fillbox{\frac{\fillbox{1}}{\fillbox{2}}}\fillbox{\cdot}
\fillbox{a}_{\fillbox{x}}\fillbox{\cdot}%
\fillbox{\Delta}\fillbox{t}^{\fillbox{2}}\fillbox{)} \fillbox{+}
\fillbox{(}\fillbox{v}_{\fillbox{x}}\fillbox{\cdot}%
\fillbox{\Delta}\fillbox{t}\fillbox{)}$\fillbox{;}\par
$\fillbox{v}_{\fillbox{x}}
\mathrel{\stackrel{\fillbox{_{~+}}}{\fillbox{\leftarrow}}}
\fillbox{a}_{\fillbox{x}}\fillbox{\cdot}%
\fillbox{\Delta}\fillbox{t}$\fillbox{;}\par
\vskip1em
$p_x \mathrel{\stackrel{_{~+}}{\leftarrow}}
(\frac{1}{2}\cdot a_x\cdot\Delta t^2) + (v_x\cdot\Delta t)$;\par
$v_x \mathrel{\stackrel{_{~+}}{\leftarrow}} a_x\cdot\Delta t$;\par
\end{document}
Producing
You can stick to your "MS Word's 2 column 1 row table" approach:
\documentclass[11pt]{article}
\usepackage[margin=1in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\begin{figure}[t]
\begin{tabular}{|p{\dimexpr.5\linewidth-2\tabcolsep}|p{\dimexpr.5\linewidth-2\tabcolsep}}
\cline{1-1}
\lipsum[1] & \lipsum[2] \\ \cline{1-1}
\end{tabular}
\end{figure}
\begin{figure}[t]
\begin{tabular}{p{\dimexpr.5\linewidth-2\tabcolsep}|p{\dimexpr.5\linewidth-2\tabcolsep}|}
\cline{2-2}
\lipsum[1] & \lipsum[2] \\ \cline{2-2}
\end{tabular}
\end{figure}
\end{document}
The two figure
s in the above MWE contains a boxed left and right block, respectively. Since both cells (regardless of content) is set inside a 1 x 2 table, the sizes will expand according to the same rules as in your requirement.
The tabular
is constructed with only 2 p
aragraph columns of width .5\linewidth-2\tabcolsep
, which makes it fit inside the text block exactly. \cline
draws a horizontal rule across the specified columns.
Best Answer
A
tcbox
fromtcolorbox
could be a solution