防止 LaTeX 列表在逗号和点之前换行

防止 LaTeX 列表在逗号和点之前换行

我有一个 PostgreSQL 脚本,我使用 listings 包将其插入到文章中,在尝试格式化代码样式时我不断遇到两个问题:点之前的换行符以及逗号或空格。

这是我当前的代码片段,它给出了近乎令人满意的结果:

\documentclass[12pt,a4paper]{article} % Spécifie le type de document et la taille du texte
\usepackage{graphicx} % Pour insérer des images
\usepackage[french]{babel} % Pour formater le texte selon la langue fr
\usepackage{listings} % Pour insérer du code
\usepackage{xcolor}    % Required for defining custom colors
\usepackage[utf8]{inputenc}  % Encodage des entrées en UTF-8
\usepackage[T1]{fontenc}     % Encodage des polices en T1 (requis pour les caractères spéciaux)
\usepackage[colorlinks=true,linkcolor=black,urlcolor=blue]{hyperref} % Pour créer des liens
\usepackage{adjustbox} % Scaler et resize des images

\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{HTML}{C42043}
\definecolor{backcolour}{HTML}{F2F2F2}
\definecolor{bookColor}{cmyk}{0,0,0,0.90}  
\color{bookColor}
\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{codepurple},
    stringstyle=\color{codepurple},
    basicstyle=\footnotesize,
    breaklines=true,
    breakautoindent=false
    captionpos=b,
    keepspaces=true,
    numbersep=10pt,
    showspaces=false,
    showstringspaces=false,
    columns=fullflexible
}

\begin{document}
\lstset{style=mystyle}`

\begin{lstlisting}[language=SQL]
DROP TABLE IF EXISTS denormalized_macp_valdavid;
CREATE TABLE denormalized_macp_valdavid AS
select
  mc.*,
  cm.mediacondid,cm.image_reference,cm.image_path,cm.video_file,cm.video_file_path,
  mi.isimperial, mi.inspection_status, mi.inspectionlevel, mi.surveyed_by, mi.certificate_number, mi.reviewed_by, mi.reviewer_certificate_number, mi.customer, mi.po_number, mi.workorder, mi.media_label, mi.project, mi.inspection_date, mi.inspection_time, mi.sheet_number, mi.weather, mi.precleaning, mi.date_cleaned, mi.purpose, mi.consequence_of_failure, mi.drainage_area, mi.manhole_number, mi.street, mi.city, mi.location_code, mi.surface_type_asphalt, mi.surface_type_concretepavement, mi.surface_type_concretecollar, mi.surface_type_grassdirt, mi.surface_type_gravel, mi.surface_type_other, mi.inflow_potential_from_runoff, mi.location_details, mi.mh_use, mi.access_type, mi.year_constructed, mi.year_renewed, mi.evidence_surcharge, mi.rim_to_invert, mi.grade_to_invert, mi.rim_to_grade, mi.rim_to_grade_exposed, mi.northing, mi.easting, mi.elevation, mi.coordinate_system, mi.vertical_datum, mi.gps_accuracy, mi.additional_info, mi.cover_condition_sound, mi.cover_condition_missing, mi.cover_condition_boltsmissing, mi.cover_condition_broken, mi.cover_condition_corroded, mi.cover_condition_cracked, mi.cover_condition_restraint_defective, mi.cover_condition_restraint_missing, mi.cover_type_bolted, mi.cover_type_gasketed, mi.cover_type_hatch_double, mi.cover_type_hatch_single, mi.cover_type_inner_cover, mi.cover_type_lamphole, mi.cover_type_locking, mi.cover_type_removable_center, mi.cover_type_solid, mi.cover_type_vented, mi.cover_shape, mi.cover_size, mi.center_cover_size, mi.cover_size_width, mi.cover_material, mi.hole_diameter, mi.hole_number, mi.cover_bearing_surface_dia, mi.cover_bearing_surface_width, mi.cover_frame_fit, mi.cover_insert_type, mi.insert_condition_sound, mi.insert_condition_cracked, mi.insert_condition_corroded, mi.insert_condition_insertfell, mi.insert_condition_leaking, mi.insert_condition_poorlyfitting, mi.adjustment_ring_type, mi.adjustment_ring_material, mi.adjustment_ring_height, mi.ring_condition_sound, mi.ring_condition_broken, mi.ring_condition_corroded, mi.ring_condition_cracked, mi.ring_condition_leaking, mi.ring_condition_poorinstall, mi.frame_condition_missing, mi.frame_condition_sound, mi.frame_condition_broken, mi.frame_condition_coated, mi.frame_condition_corroded, mi.frame_condition_cracked, mi.frame_material, mi.frame_bearing_surface_width, mi.frame_bearing_surface_depth, mi.frame_clear_open_diam, mi.frame_clear_open_width, mi.seal_condition_missing, mi.seal_condition_sound, mi.seal_condition_cracked, mi.seal_condition_loose, mi.seal_condition_offset, mi.frame_offset_distance, mi.frame_seal_inflow, mi.frame_depth, mi.chimney_present, mi.chimney_material1, mi.chimney_material2, mi.chimney_ini, mi.chimney_clear_opening, mi.chimney_depth, mi.chimney_lining_interior, mi.chimney_lining_exterior, mi.chimney_condition, mi.cone_type, mi.cone_material, mi.cone_depth, mi.cone_lining_interior, mi.cone_lining_exterior, mi.cone_condition, mi.wall_diam, mi.wall_bysize, mi.wall_material, mi.wall_depth, mi.wall_lining_interior, mi.wall_lining_exterior, mi.wall_condition, mi.bench_present, mi.bench_material, mi.bench_lining, mi.bench_condition, mi.channel_installed, mi.channel_material, mi.channel_type, mi.channel_exposure, mi.channel_condition, mi.step_number, mi.step_material, mi.additionalcomponentinfo
\end{lstlisting}
\end{document}

输出:背面预览

到目前为止,此代码的唯一问题是逗号和点之前的换行符。因为我需要能够在之后从 pdf 复制/粘贴代码。我尝试了几乎所有能找到的换行符设置,但无济于事。

咆哮:与列表相比,即使是 Overleaf 文本编辑器也显示具有出色换行符的代码。

-_-

如果有人了解这个问题我将不胜感激!

相关内容