LaTeX \rule filling the line - latex

Why does the following command not produce a horizontal rule filling the space until the end of the line?
Hello \rule[0.5em]{\fill}{1pt}
It is my understanding that this should print the text “Hello” followed by a horizontal rule that extends until the end of the line, analogously to the macro \hfill which is effectively equivalent to \hspace\fill. – But in effect, this command just produces the text “Hello”, no rule.
I am aware that the effect can be produced by \hrulefill but it can’t be used here because I want a raised rule and \hrulefill doesn’t work together with \raisebox and I want my rule to hang above the baseline (at best in the middle of the line).

I don't have a satisfying answer as to why the command you presented doesn't work, but I can offer an effective workaround. Put
% Raised Rule Command:
% Arg 1 (Optional) - How high to raise the rule
% Arg 2 - Thickness of the rule
\newcommand{\raisedrule}[2][0em]{\leaders\hbox{\rule[#1]{1pt}{#2}}\hfill}
into your document's preface, and then you can accomplish what you were hoping to with:
Hello \raisedrule[0.5em]{1pt}

The horizontal rule of 1pt height and raised by 1.5pt.
Hello \leaders\vrule height 2.5pt depth -1.5pt \hfill \null

There is a package called ulem which does this
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass{article}
\usepackage[normalem]{ulem}
\begin{document}
normal text \uline{\textit{underline text}\hfill}
\end{document}
which will produce
For your curiosity, the option normalem for package ulem prevents ulem to produce extra underline with \em or \emph.

You can do this with the command \hrulefill
see http://en.wikibooks.org/wiki/LaTeX/Lengths#Fill_the_rest_of_the_line

% I did it!
%
\documentclass{article}
\usepackage[normalem]{ulem}
\begin{document}
\uline{Some text \hfill\phantom{.}}
\end{document}

Related

LaTex how to edit this equation?

I'm having issues turning this word equation into a LaTex equation. It's coming out looking dodgy, please help!
I added a screen shot of the equation I want, and what I end up getting when I copy and paste into LaTex:
WORD:
LATEX CODE:
\mathrm{=\ }\mathrm{C}_\mathrm{0}\mathrm{[1-}6(Dt)1/2aπ2-3Dta2] + 12(Dt)1/2an = 1∞exp(na(Dt)1/2)
and therefore nothing comes out and LaTex doesn't let me run it.
This is absolutely not a proper LaTeX equation code. I don't know what you know about LaTeX, but you cannot just copy and paste from Word or any software to you LaTex editor. Plus, you need to provide your full code for anyone being able to help you.
Anyway, running this MWE should work :
\documentclass[11pt, a4paper, twoside]{report}
% ===== PACKAGES DECLARATION =====
\usepackage{mathtools} % Replaces amsmaths + more features
\usepackage{amsfonts} % Maths fonts package
% ===== DOCUMENT BODY =====
\begin{document}
\begin{equation} % optional : use the "equation*" environment to remove equation number
% optional : use traditional math font by removing the \mathrm{} command
\mathrm{X = C_0 \left[ 1 - \frac{6(Dt)^{1/2}}{a \pi^2} - \frac{3Dt}{a^2}\right] + \frac{12(Dt)^{1/2}}{a} \sum_{n=1}^\infty \exp\left(\frac{na}{(Dt)^{1/2}} \right)}
% optional : remove auto-sized brackets by removing the \left and \right commands
\end{equation}
\end{document}
As written in the code, you may want to remove the equation number and the big auto-sized brackets (that are more readable in my opinion). Just remove the corresponding commands. Also, you should consider using the "normal" math font and not the roman one that is clearly different from the text and helps the reader to separate equations from inline small expressions you could insert in your document.
One first sketch:
\documentclass{article}
\begin{document}
\[
C_0\left[1-\frac{6(Dt)^{\frac{1}{2}}}{a\pi^2}-\frac{3Dt}{a^2}\right]+%
\frac{12(Dt)^{\frac{1}{2}}}{a}\sum^{\infty}_{n=1}%
\exp\left(\frac{na}{(Dt)^{\frac{1}{2}}}\right)
\]
\end{document}
No packages required. The output:
Than you can tune the math fonts and anything else.

What does the symbol # mean in latex

for example
\def\if#nch#mpty#1{\def\temp#a{#1}\ifx\temp#a\#empty}
\def\f#nch#def#1#2{\if#nch#mpty{#2}\f#nch#gbl\def#1{\leavevmode}\else
\f#nch#gbl\def#1{#2\strut}\fi}
What does the symbol # mean in latex
By default in a TeX document, a command (also called a macro) can be only named using the letters [a-zA-Z] but not symbols such as #.
Why is that? Because each character has a category code (or catcode, for short), and by default only [a-zA-Z] have the catcode 11 that allows it to be used in a macro. But, amazingly, TeX allows you to change a character's catcode! So at the beginning of cls/sty files, LaTeX sets the catcode for # to catcode 11. Afterward, it resets it back to the default.
LaTeX also includes two commands \makeatletter and \makeatother to easily change the catcode of #.
For example:
\makeatletter
% This is ok define new command with at character.
\def\command#with#at#character{%
Command With At Character.%
}
% And you can use it in the pair makeatletter/makeatother
\command#with#at#character
\makeatother
% But you CANNOT use the macro here!!! TeX will try to call \command
% but not \command#with#at#character, because `#` now does not have
% right catcode.
% \command#with#at#character
See What do \makeatletter and \makeatother do?
to get more information.
About the macro \catcode(which can help you to change the character's catcode), you can get more information from here.

Missing number treated as zero error when using titlesec package and tableofcontents

Whenever I use the package titlesec and later the command \tableofcontents I get the following error:
I created the following MRE below
! Missing number, treated as zero. <to be read again>}\tableofcontents
In the past this never happened, but since I installed MikTex on my new laptop, those lines below do not work anymore.
Removing the package titlesec seems to work, but I would rather know the actual reason for this problem.
\RequirePackage{fix-cm}
\documentclass[
%draft,
pdftex,
paper=a4,
%paper=portait, % Paper Setting
pagesize=auto,
fontsize=11pt, % Font Size
version=last, % Version
%headsepline, % Line after header
%footsepline, % Line before footer
]{scrartcl}
\KOMAoptions{parskip=true}
% Depth of content table
\usepackage{titlesec}
\begin{document}
\tableofcontents
\newpage
Test
\end{document}

Left justification of nomenclature description in LaTeX

I'm using a LaTeX template (provided by ASME) to write a conference paper.
The asme2e.cls class defines a "nomenclature" environment as follows:
% Nomenclature environment
\newbox\tempbox
\newenvironment{nomenclature}{%
\newcommand\entry[2]{%
\setbox\tempbox\hbox{##1.\quad}
\hangindent\wd\tempbox\noindent{##1}\quad\ignorespaces##2\par}
\section*{NOMENCLATURE}}{\par\addvspace{12pt}}
which is used, in the .tex source file, as follows:
\begin{nomenclature}
% [...]
\entry{$C_{visc}$}{Viscous friction coefficient.}
\entry{$M$}{Spool mass.}
% [...]
\end{nomenclature}
resulting in the description texts not being left justified (since a fixed horizontal space is inserted between the symbol (e.g.: M) and the description (e.g.: Spool mass.), but the symbols have different lengths (e.g.: Cvisc is longer than M).
Is there a way to fix the class to have left-justified descriptions?
(I did a few experiments with \dimexpr and the calc package, but just got a bunch of errors).
(I also asked ASME if they could provide an updated template, but I'm still waiting for their feedback...)
I couldn't solve the problem, but I found a "quick and dirty" workaround, using the Tabbing and setspace packages.
Here is the new .tex source:
%[...]
\usepackage{Tabbing}
\usepackage{setspace}
%[...]
\begin{nomenclature}
{\setstretch{1.1}
\begin{tabbing}
\noindent
% [...]
\entry{$C_{visc}$}\quad\quad\={Viscous friction coefficient.}\\
\entry{$M$}\>{Spool mass.}\\
\entry{$v$}\>{Spool velocity.}\\
% [...]
\end{tabbing}
} % end \setstretch
\end{nomenclature}
%[...]
(Clearly, I'm completely bypassing the \entry command defined by the asme2e.cls class for the nomenclature environment).
I also tried to edit the asme2ej.cls file but nothing working for me. Then I ended up using the tabbing and set space packages. However, I did not use the \setstretch, and my document compiled just fine.
%[...]
\usepackage{Tabbing}
\usepackage{setspace}
%[...]
\begin{nomenclature}
\begin{tabbing}
\noindent
\entry{XYZ}\quad\quad\={This is an example}\\
\entry{PQR}\>{This is an example}\\
\entry{ZXC}\>{This is an example}\\
\entry{CVN}\>{This is an example}\\
\end{tabbing}
\end{nomenclature}
%[...]
I ran into a similar issue when submitting a paper to an ASME journal. My solution was to edit the asme2e.cls file:
\newenvironment{nomenclature}{%
\newcommand\entry[2]{\noindent\hbox to 0.05\textwidth{##1}\ignorespaces##2\par}
\section*{Nomenclature}}{\par\addvspace{12pt}}
You can change the amount of indentation by changing "0.05\textwidth".
I'm not sure if this is what you're asking, but see the following MWE:
\documentclass[12pt]{article}
\newlength{\nomenlabelindent}
\setlength{\nomenlabelindent}{4em}
\newenvironment{nomenclature}{%
\newcommand\entry[2]{%
\hangindent\nomenlabelindent\noindent\makebox[\nomenlabelindent][l]{##1\quad}\ignorespaces##2\par}%
\section*{NOMENCLATURE}}{\par\addvspace{12pt}}
\begin{document}
\begin{nomenclature}
\entry{$A$} {Parameter}
\entry{$B$} {Parameter}
\entry{$C$}{Parameter}
\entry{$D$}{Parameter}
\entry{$E$}{Parameter}
\end{nomenclature}
\end{document}
Output:
Nomenclature

part lettering Latex

I am trying to get my document parts to show up as:
A. Narrative % \part{Narrative}
Intro %\section{Intro}
main text...
B. Appendix % \part{Appendix}
Derivations % \section{Derivations}
appendix text...
I have seen others use:
\renewcommand{\thepart}{\Alph{part}}
However this is not working for me for some reason. My parts are showing up as:
Part A
Narrative
Intro
main text...
Part B
Appendix
Derivations
appendix text...
Any ideas anyone?
The minimal example below updates \part to set its numbering differently. More specifically, it removes the \partname - Part - prefix and keeps the title on the same line. Fonts are also updated to set the part using \LARGE\bfseries in both \part and \part*. All of the above updates are done using etoolbox's \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} macro that performs a <search>-and-<replace> within <cmd>.
\documentclass{article}
\usepackage{lipsum,etoolbox}
\renewcommand{\thepart}{\Alph{part}}
\makeatletter
% Change part display; also uniform size of \LARGE\bfseries
\patchcmd{\#part}% <cmd>
{\Large\bfseries \partname\nobreakspace\thepart \par\nobreak}% <search>
{\LARGE\bfseries \thepart.\quad}% <replace>
{}{}% <success><failure>
\patchcmd{\#part}{\huge}{\LARGE}{}{}
\patchcmd{\#spart}{\huge}{\LARGE}{}{}
\renewcommand{\#seccntformat}[1]{\csname the#1\endcsname.\quad}
% \#addtoreset{section}{part} % Reset section counter with every part
\makeatother
\begin{document}
\part{Narrative}
\section{Intro}
\lipsum[1]
\part{Appendix}
\section{Derivations}
\lipsum[2]
\end{document}
If you wish to have the \section numbers reset with every new \part, uncomment the line referencing that in the preamble.
Your idea is right, but you also redefine the titleformat.
From the following link:
\usepackage{titlesec}
\renewcommand{\thepart}{\Alph{part}}
\makeatletter
\titleformat{\part}[display]
{\Huge\scshape\filright}
{\thepart~\partname}
{20pt}
{\thispagestyle{plain}}
\makeatother

Resources