Math & ScienceControlling Size of '\overline' or '\bar' Command

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm

Controlling Size of '\overline' or '\bar' Command

Post by hbaromega »

I am trying to put a bar over a letter. Say, for example, in case of writing a complex conjugate of $z$ as $\bar{z}$.

However, I find it appears smaller in length (less than the width of the letter) and the bar is not clearly visible. Now if I use \overline instead, then it seems to exceed the width of the letter.

Is there something intermediate or in general, can I modify the length of the \bar or \overline ?

Thanks.
Last edited by hbaromega on Fri Nov 18, 2011 8:51 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm

Re: Controlling Size of '\overline' or '\bar' Command

Post by hbaromega »

I guess, this post has been overlooked. Please let me know whether any solution exists.

Thanks.
hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm

Re: Controlling Size of '\overline' or '\bar' Command

Post by hbaromega »

I wonder why I am not receiving any comment or reply! Is not it appearing in the topics?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Controlling Size of '\overline' or '\bar' Command

Post by localghost »

hbaromega wrote:I wonder why I am not receiving any comment or reply! […]
Solutions can only be provided if they are present. And people who work out these solutions do that in their spare time. Furthermore you are not the only one here who is asking for a solution to a problem. Perhaps you can take that into account for your next question.

A relative simple solution would be to define a new command that just draws a line with fixed sizes above an expression.

Code: Select all

\documentclass{article}

\newcommand*\oline[1]{%
  \vbox{%
    \hrule height 0.5pt%                  % Line above with certain width
    \kern0.25ex%                          % Distance between line and content
    \hbox{%
      \kern-0.1em%                        % Distance between content and left side of box, negative values for lines shorter than content
      \ifmmode#1\else\ensuremath{#1}\fi%  % The content, typeset in dependence of mode
      \kern-0.1em%                        % Distance between content and left side of box, negative values for lines shorter than content
    }% end of hbox
  }% end of vbox
}

\begin{document}
  $\oline{\alpha}$ \oline{\beta}
\end{document} 
Note that the command can be used in text mode as well as in math mode. But its argument will always be typeset in math mode.

A more complex solution is given at another place [1]. It is also more flexible due to possible customization.

[1] {TeX} SX — The \bar and \overline commands


Thorsten
hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm

Re: Controlling Size of '\overline' or '\bar' Command

Post by hbaromega »

Thanks Thorsten. I had been thinking that somehow my post did not appear.

Could you tell me where I should make change to vary the length of the bar?

Thanks a lot.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Controlling Size of '\overline' or '\bar' Command

Post by localghost »

hbaromega wrote:[…] I had been thinking that somehow my post did not appear. […]
Can't comprehend that. Either look in the sub-forum where you posted or just view the active topics (see main menu on the right side of each page here).
hbaromega wrote:[…] Could you tell me where I should make change to vary the length of the bar? […]
Actually I thought that my comments in the code should help. The relevant part is the horizontal box.

Code: Select all

\hbox{%
  \kern-0.1em%                        % Set screw for the left side
  \ifmmode#1\else\ensuremath{#1}\fi%  % The box content
  \kern-0.1em%                        % Set screw for the right side
}% end of hbox
I suggest that you play around with the set screws to find out a bit about their behaviour. The current settings mean that the line above the box is 0.2em (2·0.1em) narrower than the width of the box (determined by its content).
hbaromega
Posts: 48
Joined: Mon Mar 07, 2011 8:21 pm

Re: Controlling Size of '\overline' or '\bar' Command

Post by hbaromega »

Thanks a lot. I got it. It's working.
Post Reply