MikTex lstlisting package with quotes - latex

I'm using the beamer class to create slides and using the lstlisting package inside a colorbox. Below is a reproducible example showing my problem when using pdflatex. I'm trying to use quotes (") as in the line read.csv(c:'//path') and the compiler breaks. Things works when the quotes are removed.
Does anyone see a way to solve that problem?
\documentclass[]{beamer}
\usepackage{colortbl}
\usepackage{bm}
\usepackage{color}
\usepackage{amssymb,amsmath}
\usepackage{mathtools}
\usepackage{float}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\usepackage{tcolorbox}
\usepackage{graphicx}
\usepackage{fancybox}
\usepackage{hyperref}
% For formatting R code
\lstset{language=R,
basicstyle=\small\ttfamily,
stringstyle=\color{DarkGreen},
otherkeywords={0,1,2,3,4,5,6,7,8,9},
morekeywords={TRUE,FALSE},
deletekeywords={data,frame,length,as,character},
keywordstyle=\color{blue},
commentstyle=\color{DarkGreen},
xleftmargin=.0in,
breaklines=true,
xrightmargin=.25in
}
\newcommand{\qq}{\symbol{34}}
%\documentclass[handout]{beamer}
\mode<handout>
{
\usetheme{default}
}
\mode<presentation>
{
\usetheme{Madrid}
%\usetheme{default}
}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
%\usepackage{SweaveSlides}
\usepackage{bm}
\usepackage{graphicx}
\usefonttheme[onlymath]{serif}
%\logo{\includegraphics[width=3cm]{logo.jpeg}}
\title{Title}
\author {Name\\Place}
\institute[Place]{
}
\date[Test]{Test}
\subject{OP}
\AtBeginSubsection[]%
{
\begin{frame}<beamer>
\frametitle{Outline}
\tableofcontents[currentsection,currentsubsection]
\end{frame}
}
\begin{document}
\begin{frame}
\titlepage
\end{frame}
\begin{frame}[fragile]
\frametitle{Title}
\begin{itemize}
\item Item 1
\end{itemize}
\begin{tcolorbox}[colback=red!5,colframe=red!75!black,title=Reading in a .csv File]
\lstset{tabsize=2}
\begin{lstlisting}
read.csv('c://test')
\end{lstlisting}
\end{tcolorbox}
\end{frame}
\end{document}

Related

Long s in pdfLaTex

I am trying to mock an antique writing style in LaTex (standard Overleaf with pdfLaTex) and I need to include the old "long s" letter (https://en.wikipedia.org/wiki/Long_s). Using the ſ symbol produces the LaTeX Error: Unicode character ſ (U+017F) error.
Here's a minimal example with my actual header, thank you for any suggestion:
\documentclass[a4paper,11pt,twoside,titlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage[sorting=none]{biblatex}
\usepackage{booktabs}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{enumitem}
\usepackage{epigraph}
\usepackage{subfiles}
\begin{document}
Here is a ſimple example
\end{document}
The easiest way to use unicode characters in latex is to switch to an unicode aware engine such as lualatex or xelatex. In overleaf, you can switch to them in the sidebar of your project.
If you use one of these engines, you should remove the fontenc package.
% !TeX TS-program = lualatex
\documentclass[a4paper,11pt,twoside,titlepage]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage[labelfont=bf]{caption}
\usepackage{subcaption}
\usepackage[sorting=none]{biblatex}
\usepackage{booktabs}
\usepackage[english]{babel}
\usepackage{csquotes}
%\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{enumitem}
\usepackage{epigraph}
\usepackage{subfiles}
\begin{document}
Here is a ſimple example
\end{document}

How could I list the subsections in beamer (table of contens)?

Hello I trying to list the subsections in table of contents (beamer), but I can't get the result ? Anyone knows how to do it ?
My code (I am using the \usetheme{CambridgeUS}):
\documentclass[handout,10pt,aspectratio=169]{beamer}
\usepackage[spanish]{babel}
\usepackage{multirow,rotating}
\usepackage{color}
\usepackage{hyperref}
\usepackage{tikz-cd}
\usepackage{array}
\usepackage{siunitx}
\usepackage{mathtools,nccmath}%
\usepackage{etoolbox, xparse}
\usecolortheme{dolphin}
\usepackage{lipsum}
\usepackage{natbib}
\usepackage{hyperref}
\usepackage{calc}
\usepackage{environ}
\usepackage{courier}
\usepackage{tcolorbox}
\usetheme{CambridgeUS}
\title[]{\textcolor{black}{\vskip 1.5cm\textbf {Title}}}
\begin{document}
\begin{frame}
\maketitle
\end{frame}
\begin{frame}
\frametitle{Contenido}
\tableofcontents
\end{frame}
\section{Introducción}
\begin{frame}{Introducción}
\subsection{sismos lentos}
\end{frame}
\end{document}
Never use sectioning commands like \section or \subsection within a frame. They must be used outside the frame.
Apart from this problem, you can use https://stackoverflow.com/a/74094309/2777074 to get squares in the toc:
\documentclass[handout,10pt,aspectratio=169]{beamer}
\usepackage[spanish]{babel}
\usepackage{multirow,rotating}
%\usepackage{color}
%\usepackage{hyperref}
\usepackage{tikz-cd}
\usepackage{array}
\usepackage{siunitx}
\usepackage{mathtools,nccmath}%
\usepackage{
%etoolbox,
xparse}
\usecolortheme{dolphin}
\usepackage{lipsum}
\usepackage{natbib}
%\usepackage{hyperref}
\usepackage{calc}
\usepackage{environ}
\usepackage{courier}
\usepackage{tcolorbox}
\usetheme{CambridgeUS}
\title[]{\textcolor{black}{\vskip 1.5cm\textbf {Title}}}
\setbeamertemplate{sections/subsections in toc}[square]
\begin{document}
\begin{frame}
\maketitle
\end{frame}
\begin{frame}
\frametitle{Contenido}
\tableofcontents
\end{frame}
\section{Introduccion}
\subsection{sismos lentos}
\begin{frame}{Introduccion}
\end{frame}
\end{document}

Citation in figure caption showing up as text in list of tables

When using \cite in a caption for a figure, the citation shows up as the citation number in the caption (as it should) but as text in the list of figures. I never ran into this problem before so I'm not sure what's going on.
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{fullpage}
\usepackage{subcaption}
\usepackage{natbib}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{float}
\usepackage{comment}
\usepackage[table,xcdraw]{xcolor}
\usepackage{pdfpages}
\usepackage{makecell}
\usepackage{textcomp}
\usepackage{siunitx}
\usepackage{graphicx,changepage}
\usepackage{setspace}
\usepackage{chngcntr}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage[thinlines]{easytable}
\usepackage{tabularx}
\usepackage{tocloft}
\usepackage[normalem]{ulem}
\begin{document}
\makeatletter
\renewcommand{\l#table}{\#dottedtocline{1}{1.5em}{2.5em}}
\makeatother
\listoftables
\begin{figure}[H]
\centering
\includegraphics [width=0.7\textwidth] {Images/cnc-processing-center-centateq-p-110_01.jpg}
\caption{Homag Centateq P-110 \cite{HOMAG}}
\label{fig:cnc_mill}
\end{figure}
\end{document}
i tried compiling your code on overleaf, to do that, i added some lines on your code as is show following:
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{fullpage}
\usepackage{subcaption}
\usepackage{natbib}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{float}
\usepackage{comment}
\usepackage[table,xcdraw]{xcolor}
\usepackage{pdfpages}
\usepackage{makecell}
\usepackage{textcomp}
\usepackage{siunitx}
\usepackage{graphicx,changepage}
\usepackage{setspace}
\usepackage{chngcntr}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage[thinlines]{easytable}
\usepackage{tabularx}
\usepackage{tocloft}
\usepackage[normalem]{ulem}
\begin{document}
\makeatletter
\renewcommand{\l#table}{\#dottedtocline{1}{1.5em}{2.5em}}
\makeatother
\listoftables
\listoffigures %added to provide a list of figures
\begin{figure}[H]
\centering
\includegraphics [width=0.7\textwidth] {test.pdf}
\caption{Homag Centateq P-110 \cite{HOMAG}}
\label{fig:cnc_mill}
\end{figure}
\begin{thebibliography}{9} % Added the thebibliography enviromment to use Homag as exemple.
\bibitem{HOMAG}
Homag.
\end{thebibliography}
\end{document}
As is shown on the figure above, the list of figures is like you want. I suspect that you have troubles with your LaTex compiler, try do a upgrade on your compiler or use another, like overleaf.

Unwanted blank page before title in Latex

there is an Unwanted blank page before title in Latex, and I don't understand why there are string "_result_result" in this blank page, I am pretty sure I didn't add them
Here is my code.
**I am editing in overleaf and using LuaLaTex **
\documentclass[letterpaper,twocolumn,12pt]{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,chains}
\usepackage{cite}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfigure}
\usepackage{fontspec}
\usepackage{underscore}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{array}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{textcomp}
\usepackage{pgfplots}
\usepackage{indentfirst}
\setlength{\parindent}{2em}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{subfigure}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{subcaption}
\geometry{centering,textwidth=0.887589cm,columnsep=.81cm,left=1.6cm,right=1.6cm,top=1.91cm,bottom=2.54cm}
\pagenumbering{gobble}
\usepackage{verbatim}
\newtheorem{definition}{Definition}
\usepackage{titlesec}
\usepackage[]{caption2}
\renewcommand{\figurename}{Fig.}
\renewcommand{\captionlabeldelim}{.~}
\renewcommand{\thesubfigure}{Figure.\arabic{figure}(\alph{subfigure})}
\makeatletter \renewcommand{\#thesubfigure}{\thesubfigure\space}
\renewcommand{\p#subfigure}{} \makeatother
\titleformat*{\section}{\normalsize\centering\textbf}
\titleformat*{\subsection}{\indent\small\centering\textbf}{\hspace{1cm}}
\renewcommand\thesection{\Roman{section}.}
\renewcommand\thesubsection{\arabic{subsection}.}
\newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}}
\newcommand{\tnewroman}{\fontspec{Times New Roman}}
\providecommand{\keywords}[1]
{
\footnotesize
\textbf{Key words --} #1
}
\providecommand{\abstrct}[1]
{
\footnotesize
\textbf{Abstract --} #1
}
\newcommand{\tabincell}[2]{\begin{tabular}{#{}#1#{}}#2\end{tabular}}
\setlength{\parskip}{0.5\baselineskip}
%set font style
\setmainfont{Times New Roman}
%set title and author
\title{\vspace{-1cm}My title}
%begin the document
\begin{document}
\maketitle
the unwanted blank page
Please don't ignore the errors and warnings in the .log file. they exactly tell you which of your package are incompatible and which commands are missing.
To summarise the changes:
lots of incompatible packages
syntax errors in \titleformat. In particular you must not write \titleformat{}{}
writing \textbf some text is wrong. It is a macro so you either need \textbf{some text} or \bfseries some text
you should clean up your preamble, many of the packages are redundant, make no sense or are loaded multiple times.
% !TeX TS-program = xelatex
\documentclass[letterpaper,twocolumn,12pt]{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,chains}
\usepackage{cite}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfigure}
\usepackage{fontspec}
\usepackage{underscore}
\usepackage{ragged2e}
\usepackage{geometry}
\usepackage{array}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{textcomp}
\usepackage{pgfplots}
\usepackage{indentfirst}
\setlength{\parindent}{2em}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{subfigure}
\usepackage[font=footnotesize,labelfont=bf]{caption}
%\usepackage{subcaption}
\geometry{centering,textwidth=0.887589cm,columnsep=.81cm,left=1.6cm,right=1.6cm,top=1.91cm,bottom=2.54cm}
\pagenumbering{gobble}
\usepackage{verbatim}
\newtheorem{definition}{Definition}
\usepackage{titlesec}
%\usepackage[]{caption2}
\renewcommand{\figurename}{Fig.}
%\renewcommand{\captionlabeldelim}{.~}
\renewcommand{\thesubfigure}{Figure.\arabic{figure}(\alph{subfigure})}
\makeatletter \renewcommand{\#thesubfigure}{\thesubfigure\space}
\renewcommand{\p#subfigure}{} \makeatother
\titleformat*{\section}{\normalsize\centering\bfseries}
\titleformat*{\subsection}{\indent\small\centering\bfseries\hspace{1cm}}
\renewcommand\thesection{\Roman{section}.}
\renewcommand\thesubsection{\arabic{subsection}.}
\newcommand{\upcite}[1]{\textsuperscript{\textsuperscript{\cite{#1}}}}
\newcommand{\tnewroman}{\fontspec{Times New Roman}}
\providecommand{\keywords}[1]
{
\footnotesize
\textbf{Key words --} #1
}
\providecommand{\abstrct}[1]
{
\footnotesize
\textbf{Abstract --} #1
}
\newcommand{\tabincell}[2]{\begin{tabular}{#{}#1#{}}#2\end{tabular}}
\setlength{\parskip}{0.5\baselineskip}
%set font style
\setmainfont{Times New Roman}
%set title and author
\title{\vspace{-1cm}My title}
\author{names}
%begin the document
\begin{document}
\maketitle
\justifying
%%
\begin{thebibliography}{00}
\bibitem{1}My bib
\end{thebibliography}
\end{document}

How to eliminate brackets from caption for subfigures in latex?

The problem I have is that when I compile the image caption is displayed with brackets "[fig caption]".......................................................................................................................................
\documentclass{elsarticle}
\usepackage{verbatim}
\usepackage{xcolor}
\usepackage{booktabs} % For professional looking tables
\usepackage{multirow}
\usepackage{siunitx}
\usepackage{framed}
\usepackage{longtable}
\usepackage{lscape}
%\usepackage[ruled,vlined]{algorithm2e}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{amsmath}
%\usepackage[ruled,vlined]{algorithm2e}
\usepackage{slashbox}
\usepackage{caption}
\usepackage{natbib}
\usepackage{graphicx}
\usepackage{float}
%\usepackage{subcaption}
\usepackage{subfig}
\usepackage{multirow}
\usepackage{bigstrut}
\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
\usepackage{lineno,hyperref}
\usepackage{cleveref}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\modulolinenumbers[5]
\journal{Journal of \LaTeX\ Templates}
\usepackage{blindtext}
\usepackage{amssymb}
\usepackage{amsthm}
\begin{figure}
\subfigure[]{ \includegraphics[width=0.24\textwidth]{graph1}
}
\subfigure[]{\includegraphics[width=0.24\textwidth]{graph2}%
}
\subfigure[]{\includegraphics[width=0.24\textwidth]{graph3}}%
\caption{Three simple graphs}
\label{fig:three graphs}
\end{figure}
This issue has been addressed at Tex Stack Exchange, see here.
The proposed solution is to use the subcaption package, instead of subfig.
I had the same issue and found a solution here: https://answerbun.com/tex-latex/latex-how-to-remove-round-brackets-in-the-caption-of-subfigures-using-subfloat/
I used the following package:
\usepackage[caption=false]{subfig}
And the following structure:
\begin{figure}[H]
\captionsetup[subfloat]{labelformat=simple} %% Do not forget this command!
\centering
\subfloat[]{\includegraphics[width=0.49\textwidth]{fig1}}\hfill
\subfloat[]{\includegraphics[width=0.49\textwidth]{fig2}}\hfill \\
\subfloat[]{\includegraphics[width=0.49\textwidth]{fig3}}
\caption{General caption.} \label{fig:1}
\end{figure}
It worked for me!

Resources