8

The following code

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\begin{document}
\[
\left[\underline{x},\bar{x}\right]
\]
\[
\left[\underline{t},\bar{t}\right]
\]
\end{document}

produces the following result:

enter image description here

I'd like to 'fix' the \underline{x} length, which is bigger than \bar{x}, and the \bar{t} which (almost!) overlaps with part of \right] compared to \underline{t} which appears nice with the \left[.

Using pdfLaTeX.

Mico
  • 506,678
niels
  • 3,295

3 Answers3

8

Without additional packages. These macros correct width of a box with a slanted entry.

\documentclass{article}

\begin{document}

\newdimen\slantmathcorr
\def\oversl#1{%assuming that mathslant=0.25
\setbox0=\hbox{$#1$}
\slantmathcorr=\wd0
\hskip 0.2\slantmathcorr \overline{\hbox to 0.8\wd0{%
\vphantom{\hbox{$#1$}}}}
\hskip-\wd0\hbox{$#1$}
}

\def\undersl#1{%assuming that mathslant=0.25
\setbox0=\hbox{$#1$}
\slantmathcorr=\wd0
\underline{\hbox to 0.8\wd0{%
\vphantom{\hbox{$#1$}}}}
\hskip-0.8\wd0\hbox{$#1$}
}

\[
\left[\underline{x},\bar{x}\right]
\]
\[
\left[\underline{t},\bar{t}\right]
\]

Corrected:

\[
\left[\undersl{x},\oversl{x}\right]
\]
\[
\left[\undersl{t},\oversl{t}\right]
\]

\end{document}

enter image description here

And once again in the version requested by OP. It can produce some side-effects.

\documentclass{article}

\begin{document}

\let\oldbar\bar
\let\oldunderline\underline
\let\oldoverline\overline


\newdimen\slantmathcorr
\def\oversl#1{%assuming that mathslant=0.25
\setbox0=\hbox{$#1$}
\slantmathcorr=\wd0
%\hskip 0.2\slantmathcorr \overline{\hbox to 0.8\wd0{%
\hskip 0.2\slantmathcorr \oldoverline{\hbox to 0.8\wd0{%
\vphantom{\hbox{$#1$}}}}
\hskip-\wd0\hbox{$#1$}
}

\def\undersl#1{%assuming that mathslant=0.25
\setbox0=\hbox{$#1$}
\slantmathcorr=\wd0
%\underline{\hbox to 0.8\wd0{%
\oldunderline{\hbox to 0.8\wd0{%
\vphantom{\hbox{$#1$}}}}
\hskip-0.8\wd0\hbox{$#1$}
}

\[
\left[\underline{x},\bar{x}\right]
\]
\[
\left[\underline{t},\bar{t}\right]
\]

Corrected:

\[
\left[\undersl{x},\oversl{x}\right]
\]
\[
\left[\undersl{t},\oversl{t}\right]
\]



\let\bar\oversl
\let\underline\undersl

\[
\left[\underline{x},\bar{x}\right]
\]
\[
\left[\underline{t},\bar{t}\right]
\]

\end{document}
  • I like your solution bro, if only you could fix the following issues: a) can \oversl{} and \undersl 'overload' \bar{} and \underline{} respectively? b) the \underline{x} bar kinda appears slightly more left than it should be. – niels Nov 08 '13 at 21:59
  • @niels a) Should I understand, that you still want to use \bar and \underline, but behaving as my \oversl ans \undersl? b) It is centered on a slanted axis of a glyph, hence a little bid moved to left. – Przemysław Scherwentke Nov 08 '13 at 22:07
  • Regarding (a): yes (but its OK I've figure it out) – niels Nov 08 '13 at 22:08
  • @niels Please see the second version after a picture. – Przemysław Scherwentke Nov 08 '13 at 22:18
5

You can use the accents package for the underbar; for the intervals, it's probably better to define your own command:

\documentclass{article}
\usepackage{accents}
\newcommand{\ubar}[1]{\underaccent{\bar}{#1}}
\newcommand{\interval}[2]{[\,#1,#2\,]}
\begin{document}
\[
\interval{\ubar{x}}{\bar{x}}
\]
\[
\interval{\ubar{t}}{\bar{t}}
\]
\end{document}

enter image description here

egreg
  • 1,121,712
2

To get "short" underlines in math mode, you could use the \ushort macro of the ushort package. To avoid a near- or full collision between \bar{t} and ], you could insert a \, ("thin space") spacer.

In the following example, the modified code in on the left and your original code is on the right.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{ushort}
\begin{document}
\[
[\ushort{x},\bar{x}] \mbox{ vs. } [\underline{x},\bar{x}]
\]
\[
[\ushort{t},\bar{t}\,] \mbox{ vs. } [\underline{t},\bar{t}]
\]
\end{document}
Mico
  • 506,678