I’m simply looking to add some padding to a st.markdown object but also preserve the ability to use LaTeX formatting. So far, I haven’t been able to figure this out. Below is what I’ve tried. I’ve also tried using a <div> tag in place of <p> as well as <style>; in all cases the padding is applied but the LaTeX formatting is lost.
Thanks for the suggestion; unfortunately, that does not quite work. It seems to add much more than 10 pixels of spacing above the text in the second markdown object. Even if adjusting to 0px with the suggested approach, it still applies more than the intended offset.
For what it’s worth, I’m trying to vertically align the text in the markdown object with text shown in a number_input widget in an adjacent column. Without some sort of padding they are vertically offset from each other.
@mliu thanks for not giving up on me! I realized the challenge becomes more apparent when the labels are collapsed for the number_input widgets. I am trying to conserve vertical screen space as much as possible, hence adding markdown in an adjacent column to serve as the widget label instead of the standard way. Below shows the result of using 0 pixels of padding, as well as what happens when turning that off.
import streamlit as st
col1, col2 = st.columns(2)
with col1:
num1= st.number_input(label = 'Insert a number', label_visibility='collapsed')
num2 = st.number_input(label = 'Insert another number', label_visibility='collapsed')
with col2:
st.markdown("<p style='padding-top:0px'></p>", unsafe_allow_html=True)
st.markdown("Height ($$H$$), inches", unsafe_allow_html=True)
st.markdown("<p style='padding-top:0px'></p>", unsafe_allow_html=True)
st.markdown("Width ($$W$$), inches", unsafe_allow_html=True)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.