6

I'm trying to write a nice number symbol (#). The usual tex way is just to put a backslash before, like this \#. The symbol that is created drops below the baseline of the rest! This is what I want to avoid.

Is there a nice package, or something else, that will allow me to write a nicer looking number symbol?

  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – user11232 Apr 4 '15 at 15:52
  • That depends on what you want it for. In text, some OpenType fonts have features that change # to № or that shrink # down to fit with oldstyle numbers. – Thérèse Apr 4 '15 at 17:00
  • I think this has to do more with the typography you decide to use. A good one has a set of non alphabetical symbol (such that) well designed instead the boring and generic design present in many others. – Aradnix Apr 4 '15 at 17:17
9

Does this look nice?

\documentclass{article}

\begin{document}
Using \verb|\verb|: \verb|#| and using \verb|\texttt|: \texttt{\#} and then regular symbol using \verb|\#|: \#

\end{document}

enter image description here

  • Yes!:) And it is more upright, which was another thing that I didn't like about the "normal" number symbol. Thanks! – Christian Olsen Apr 4 '15 at 17:27
  • Isn't it a bit too bold in comparison to the rest of the text? – Jonas Stein Apr 1 '17 at 20:26
7

And this one?

\documentclass{article}
\newcommand{\myhash}{\raisebox{\depth}{\#}}
\begin{document}
\# or \myhash?
\end{document}

enter image description here

The second hash fits your requirement (not dropping below the baseline), but personally I think the first is better positioned.

  • 4
    Anyway, a nice hash symbol is a contradiction in terms. – egreg Apr 4 '15 at 14:26
  • 1
    I agree. Compare p = \# d with p = \myhash d The depth of \# is the same that "p", and is as high as "d". In this way is too high. – Fran Apr 4 '15 at 14:30
  • You are right that your solution makes the baseline follow the normal letter baseline. But as @Fran, I don't like that it now is higher than normal letters. But anyway, thanks for posting your solution:) – Christian Olsen Apr 4 '15 at 17:29
  • @ChristianOlsen I do agree with you: placed just upon the baseline, the standard hash symbol is way too high relatively to the other letters. But you asked for it, so I got it for you :-) – Franck Pastor Apr 4 '15 at 20:00
6

A solution with TikZ. The hash sign has the width of 80% of the equals sign, see \myWidth, and the height of an uppercase letter, see \myHeight. The vertical distance of the horizontal lines is configured as a third of the width, see \mySepY. The angle of the slanted lines is configured by \myAngle. Also side bearings are added, see \mySideBearing. The line caps are round:

\documentclass{article}

\usepackage{tikz}
\newcommand*{\myhash}{%
  \begin{tikzpicture}
    % Width: 80% of equal sign
    \pgfmathsetlengthmacro\myWidth{.8*width("=")}%
    % Height: height of uppercase letter
    \pgfmathsetlengthmacro\myHeight{height("H")}%
    % Space between horizontal lines
    \pgfmathsetlengthmacro\mySepY{.3333*\myWidth}%
    % Side bearing
    \pgfmathsetlengthmacro\mySideBearing{.1*\myWidth}%
    % Angle for slanted vertical lines
    \def\myAngle{70}%
    % Calculate separation of vertical lines in horizontal direction
    \pgfmathsetlengthmacro\mySepX{\mySepY/sin(\myAngle)}%
    % Calculate the width of a slanted line
    \pgfmathsetlengthmacro\mySlantX{\myHeight/tan(\myAngle)}%
    \draw[line cap=round]
      (0, {(\myHeight - \mySepY)/2}) -- ++(\myWidth, 0)
      (0, {(\myHeight + \mySepY)/2}) -- ++(\myWidth, 0)
      ({(\myWidth - \mySepX - \mySlantX)/2}, 0)
      -- ({(\myWidth - \mySepX + \mySlantX)/2}, \myHeight)
      ({(\myWidth + \mySepX - \mySlantX)/2}, 0)
      -- ({(\myWidth + \mySepX + \mySlantX)/2}, \myHeight)
    ;%
    \useasboundingbox
      (-\mySideBearing, 0)
      (\myWidth + \mySideBearing, \myHeight)
    ;% 
  \end{tikzpicture}%
}

\begin{document}
  A\myhash B vs.\@ A\#B
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.